我遇到了问题,我相信,是无法过滤变量节点集。
我有一个变量,它填充了来自文档集合的节点集,如果输入中尚不存在这些节点,我想回显输入并添加变量节点。
<xsl:variable name="views" select="collection('file:/C:/temp/?select=*.xml;recurse=yes')"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="@* | *"/>
<!-- having trouble with the filter here never works -->
<xsl:for-each select="$views/someElement[not(@name=(//someInputElement/@name))]">
<!-- copy stuff in -->
</xsl:for-each>
</xsl:copy>
</xsl:template>
请注意,输入中将有许多具有名称属性的 someInputElement 实例。
当我对目标运行 xpath//someInputElement/@name 时,我按预期得到一个列表。
任何建议最值得赞赏。
我相信
我已经找到了答案...从我今天在其他地方找到的提示中,我添加了对根的引用并在过滤器中使用它。
<xsl:variable name="views" select="collection('file:/C:/temp/?select=*.xml;recurse=yes')"/>
<xsl:variable name="root" select="/" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="@* | *"/>
<!-- filter referring back to the root of the input -->
<xsl:for-each select="$views/someElement[not(@name=($root//someInputElement/@name))]">
<!-- copy stuff in -->
</xsl:for-each>
</xsl:copy>
</xsl:template>