如果没有值,则无法从表中删除行

时间:2019-06-14 10:49:22

标签: xslt xslt-1.0

我创建了XSLT来在表中显示属性和值。属性和值是从外部插件(MDM)中选取的。

我创建了代码,例如当属性没有值时应返回“ N / A”,但我希望得到结果,例如当属性没有值时应从表中删除完整的行。

下面的表格如下:

属性 ------>

A01 ----->(一些值),它将从MDM系统中选择。

DUP为511 ------>不适用(不适用表示MDM系统中没有值)

预期结果:

此处“ A01”和“ DUP for 511”是属性。 A01有值,而511的DUP没有值。如果MDM系统中没有值,则应删除“ DUP for 511”行。

所以最终结果应该是:

A01 ----->(有些值)。

         https://dansk-stage.adobecqms.net/services/assets.img/id/'“ />

<xsl:template name="replace-string">
    <xsl:param name="text"/>
    <xsl:param name="replace"/>
    <xsl:param name="with"/>
    <xsl:choose>
        <xsl:when test="contains($text,$replace)">
            <xsl:value-of select="substring-before($text,$replace)"/>
            <xsl:value-of select="$with"/>
            <xsl:call-template name="replace-string">
                <xsl:with-param name="text" select="substring-after($text,$replace)"/>
                <xsl:with-param name="replace" select="$replace"/>
                <xsl:with-param name="with" select="$with"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="replaceStepTags">
    <xsl:param name="inputText"/>
    <xsl:variable name="SR1">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$inputText"/>
            <xsl:with-param name="replace" select="'&lt;bulletlist&gt;'"/>
            <xsl:with-param name="with" select="'&lt;ul&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR2">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR1"/>
            <xsl:with-param name="replace" select="'&lt;/bulletlist&gt;'"/>
            <xsl:with-param name="with" select="'&lt;/ul&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR3">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR2"/>
            <xsl:with-param name="replace" select="'&lt;bullet&gt;'"/>
            <xsl:with-param name="with" select="'&lt;li&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR4">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR3"/>
            <xsl:with-param name="replace" select="'&lt;/bullet&gt;'"/>
            <xsl:with-param name="with" select="'&lt;/li&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR5">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR4"/>
            <xsl:with-param name="replace" select="'&lt;bold&gt;'"/>
            <xsl:with-param name="with" select="'&lt;b&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR6">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR5"/>
            <xsl:with-param name="replace" select="'&lt;/bold&gt;'"/>
            <xsl:with-param name="with" select="'&lt;/b&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR7">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR6"/>
            <xsl:with-param name="replace" select="'&lt;italic&gt;'"/>
            <xsl:with-param name="with" select="'&lt;i&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR8">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR7"/>
            <xsl:with-param name="replace" select="'&lt;/italic&gt;'"/>
            <xsl:with-param name="with" select="'&lt;/i&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR9">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR8"/>
            <xsl:with-param name="replace" select="'&lt;underlined&gt;'"/>
            <xsl:with-param name="with" select="'&lt;u&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR10">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR9"/>
            <xsl:with-param name="replace" select="'&lt;/underlined&gt;'"/>
            <xsl:with-param name="with" select="'&lt;/u&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR11">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR10"/>
            <xsl:with-param name="replace" select="'&lt;bolditalic&gt;'"/>
            <xsl:with-param name="with" select="'&lt;b&gt;&lt;i&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SR12">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR11"/>
            <xsl:with-param name="replace" select="'&lt;/bolditalic&gt;'"/>
            <xsl:with-param name="with" select="'&lt;/i&gt;&lt;/b&gt;'"/>
        </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="SSR1">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SR12"/>
            <xsl:with-param name="replace" select="'&lt;LineBreak/&gt;'"/>
            <xsl:with-param name="with" select="'&lt;br&gt;'"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="SSR2">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SSR1"/>
            <xsl:with-param name="replace" select="'&lt;return/&gt;'"/>
            <xsl:with-param name="with" select="'&lt;br&gt;'"/>
        </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="SSR3">
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="$SSR2"/>
            <xsl:with-param name="replace" select="'&#10;'"/>
            <xsl:with-param name="with" select="'&lt;br/&gt;'"/>
        </xsl:call-template>
    </xsl:variable>

    <xsl:value-of select="$SSR3" disable-output-escaping="yes"/>
</xsl:template>


<xsl:template match="/">
    <!-- <xsl:variable name="GoldenRecordID" select="/Product/Values/Value[@AttributeID='DataSourceGoldenRecordID']" />
    <xsl:variable name="GoldenRecordXML" select="document(concat('/webui/proofview/products/', $GoldenRecordID))" /> -->
    <xsl:variable name="context" select="/Product/@Context"/>
    <html>
        <head>
            <style>
                * { margin:0; padding: 0; } body { font-family: 'Tahoma'; background-color: #F5F5F5; font-size:
                12px; } 
                h1 { color: #666666; font-size: 26px; line-height: 30px; font-weight: bold; padding:6px; }
                h2 { font-size: 16px; line-height: 18px; color: #666666; } 
                h3 { color:#333333; font-weight: bold; font-size: 14px; line-height: 16px; width:96%; height: 16px; margin:0 0 0 0; }  
                .headline1 { color: #666666; font-size: 20px; line-height: 30px; font-weight: bold; padding:15px; }
                .headline2 { font-size: 16px; line-height: 18px; color: #666666; } 
                .headline3 { color:#333333; font-weight: bold; font-size: 14px; line-height: 16px; width:96%; height: 16px; margin:0 0 0 0; }  
                .headline4 { color:#333333; font-weight: normal; font-size: 12px; line-height: 13px; padding:10px 0 10px 25px; width:96%;
                height: 15px; margin:0 0 15px 0; background-color:#E4E4E4;} h5 { font-size: 12px; line-height: 13px;
                color:#666666; margin-left: 30px; margin-bottom: 10px; } h6 { font-size: 12px; } p { font-size:
                12px; line-height: 17px; color:#333333; width: 94%; margin-left: 30px; } .mySlides { margin:auto; display:none; }
                #main-container { margin: 20px; width:97%; min-height: 700px; padding-bottom: 50px;
                background-color: #ffffff; } #column1 { width: 50%; float: left; } #column2 {
                width: 50%; float: right; } .
                data-section { float: right; width:100%; margin:15px 25px 0 0; } 
                table { font-size: 12px; margin: left; } 
                td, th { text-align: left; padding: 8px; line-height: 1.5; vertical-align: top; border-top: 1px solid #ddd; }

            </style>
            <title>
                <xsl:value-of select="/Product/Name"/>
            </title>
        </head>
        <body>

        <div id="main-container">
          <div class="headline1"><xsl:value-of select="/Product/Name"/></div>
            <div class="data-section">

                <table id="Testing1" border="1">
                    <tr>
                        <th>A01</th>
                        <xsl:choose>
                            <xsl:when test="/Product/Values/Value[@AttributeID='A01']!= ''">
                                <td>
                                    <xsl:value-of select="/Product/Values/Value[@AttributeID='A01']/text()"/>
                                </td>   
                            </xsl:when>
                            <xsl:otherwise>
                                <td>N\A</td>
                            </xsl:otherwise>
                        </xsl:choose>
                    </tr>
                    <tr>
                        <th>Dup for 511</th>                                            
                        <xsl:choose>
                            <xsl:when test="/Product/Values/Value[@AttributeID='Dup for 511']!= ''">
                                <td>
                                    <xsl:value-of select="/Product/Values/Value[@AttributeID='Dup for 511']/text()"/>
                                </td>   
                            </xsl:when>
                            <xsl:otherwise>
                                <td>N\A</td>
                            </xsl:otherwise>
                        </xsl:choose>
                    </tr>
                </table>    

            </div>
        </div>

        </body>
    </html>
</xsl:template>

0 个答案:

没有答案