我正在使用XSLT 2.0和Apache FOP进行XSLT转换。
我的任务是创建一个变量,该变量将包含以下XML结构中唯一且已排序的类别名称:
<equipment>
<E0132>
<category>1. First Aid</category>
<description>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</description>
</E0132>
<E0133>
<category>1. First Aid</category>
<description>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</description>
</E0133>
<E4122>
<category>3. Fire safety</category>
<description>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</description>
</E4122>
<E4182>
<category>3. Fire safety</category>
<description>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</description>
</E4182>
<E4622>
<category>2. Access control</category>
<description>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</description>
</E4622>
<E5225>
<category>4. Recognition</category>
<description>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</description>
</E5225>
</equipment>
到目前为止,我所拥有的XSL代码是:
<xsl:variable name="equipment">
<xsl:for-each select="//equipment/node()/category">
<xsl:sort select="." order="ascending" />
<xsl:value-of select="distinct-values(.)"/>
</xsl:for-each>
</xsl:variable>
它解决了排序部分,但似乎distinct-values()
函数不起作用,我有重复的值。
我做错了什么?
答案 0 :(得分:2)
您需要将distinct-values
放在选择表达式
<xsl:for-each select="distinct-values(//equipment/node()/category)">
<xsl:sort select="." order="ascending" />
<xsl:value-of select="."/>
</xsl:for-each>