我创建了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="'<bulletlist>'"/>
<xsl:with-param name="with" select="'<ul>'"/>
</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="'</bulletlist>'"/>
<xsl:with-param name="with" select="'</ul>'"/>
</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="'<bullet>'"/>
<xsl:with-param name="with" select="'<li>'"/>
</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="'</bullet>'"/>
<xsl:with-param name="with" select="'</li>'"/>
</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="'<bold>'"/>
<xsl:with-param name="with" select="'<b>'"/>
</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="'</bold>'"/>
<xsl:with-param name="with" select="'</b>'"/>
</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="'<italic>'"/>
<xsl:with-param name="with" select="'<i>'"/>
</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="'</italic>'"/>
<xsl:with-param name="with" select="'</i>'"/>
</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="'<underlined>'"/>
<xsl:with-param name="with" select="'<u>'"/>
</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="'</underlined>'"/>
<xsl:with-param name="with" select="'</u>'"/>
</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="'<bolditalic>'"/>
<xsl:with-param name="with" select="'<b><i>'"/>
</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="'</bolditalic>'"/>
<xsl:with-param name="with" select="'</i></b>'"/>
</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="'<LineBreak/>'"/>
<xsl:with-param name="with" select="'<br>'"/>
</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="'<return/>'"/>
<xsl:with-param name="with" select="'<br>'"/>
</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="' '"/>
<xsl:with-param name="with" select="'<br/>'"/>
</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>