【发布时间】:2018-01-17 13:40:00
【问题描述】:
我需要遍历对象列表并在 xslt 中比较它们。如果找到匹配项,我需要停止处理文档。如果我到达列表的末尾并且没有找到匹配项,那么我需要处理文档。 问题是 xslt 变量一旦声明就不能更改。这将是一个简单的 For 循环,在其他常用语言中具有真/假变量。
<!--I need to iterate through this list-->
<xsl:variable name="exclude">
<exclude block="999" />
<exclude block="111" />
</xsl:variable>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- Here I iterate through the docs, but I don't iterate though the objects in the list.The main problem is I don't know how to search the list and make a decision at the end or when I encounter a match. This code only works on the first object "999" -->
<xsl:template match="/">
<xsl:if test="not(contains($url, exsl:node-set($exclude)/exclude/@block))">
<xsl:copy-of select="." />
</xsl:if>
</xsl:template>
【问题讨论】:
-
什么是
$url,输入文档看起来如何,在将输入映射到输出方面,您想要的结果是什么? -
$url 只是文档中的一个 url。它看起来像
它可能看起来很奇怪,但它是我正在使用的系统的一部分。“/”上的匹配基本上是根 节点上的匹配。我需要阻止在其 url 中包含特定值的文档。我可以让它在“999”而不是“111”上工作,因为我无法迭代整个排除列表。我会有 200-400 个排除节点。 -
顺便说一句,这一切都必须在 XSLT 1.0 中
标签: xml xslt watson-explorer