出于几个原因,我需要在XSLT 1.0中派生一个变量,该变量可以在转换期间重用,该变量收集重复条目的惟一列表。
输入数据在XSLT中生成到一个变量“portlist”中:
<plist>
<p>12345</p>
<p>12345</p>
<p>9876</p>
<p>12345</p>
<plist>
在我的XSLT-template中,我需要一个变量"reducedList“在转换中被多次重用。如何在XSLT中生成一个新的变量"reducedList“,如下所示
<plist>
<p>12345</p>
<p>9876</p>
<plist>
我找到了几个例子,但我必须承认我搞不懂。
我的xslt模板如下所示
<xsl:template match="stage">
<xsl:variable name="portlist" > <!-- returns a sorted list of all ports -->
<plist>
<xsl:for-each select="provider/server/QMGR"><!-- input from XML -->
<xsl:sort select="."/>
<p><xsl:value-of select="./@port"/></p>
</xsl:for-each>
</plist>
</xsl:variable>
<!-- here i need to derive the new variable reducedList -->
<!-- more code using reducedList follows here -->
</xsl:template>
发布于 2018-08-31 11:03:41
<xsl:variable name="portlist">
<plist>
<p>12345</p>
<p>12345</p>
<p>9876</p>
<p>12345</p>
</plist>
</xsl:variable>
<xsl:variable name="reducedList">
<plist>
<xsl:copy-of select="ext:node-set($portlist)/plist/p[not(text() = preceding-sibling::p/text())]"/>
</plist>
</xsl:variable>
其中ext
是带有node-set()
的扩展命名空间,例如xmlns:ext="urn:schemas-microsoft-com:xslt"
。
https://stackoverflow.com/questions/52113784
复制相似问题