【发布时间】:2012-12-07 14:31:24
【问题描述】:
我有以下模板:
<xsl:template match="footnote">
<xsl:variable name = "string">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:variable name = "bool">
<xsl:if test="$string = preceding-sibling::node()/$string">
<xsl:text>false</xsl:test>
</xsl:if>
</xsl:variable>
<xsl:if test="$bool != 'false'">
<!-- DO STUFF -->
</xsl:if>
</xsl:template>
我正在尝试检查当前节点的 $string 变量,并对照所有以前的脚注节点检查它们是否具有相同的 $string 变量。如果它与前面的任何兄弟不匹配,那么它应该做一些事情,否则它什么也不做。
使用我的代码,测试“$string =previous-sibling::node()/$string”总是评估为真,即使尚未创建脚注节点。
谁能帮帮我?我很难创建表达式来与之前所有兄弟姐妹中的变量进行比较。
编辑:示例 XML:
<xml>
<footnote>Footnote 1</footnote>
<footnote>Footnote 2</footnote>
<footnote>Footnote 1</footnote>
<footnote>Footnote 1</footnote>
<footnore>Footnote 3</footenote>
</xml>
我正在尝试将其转换为:
<xml>
<footnote>Footnote 1</footnote>
<footnote>Footnote 2</footnote>
<footnote>Footnore 3</footnore>
</xml
【问题讨论】:
-
你能添加到 queestion xml 中,这个 xslt 将被应用吗?
-
这种情况下不需要定义变量!请检查我的答案,只有模板覆盖才能消除重复的节点(值)..
标签: xslt