[英]xslt filter variable node-set using input
I'm having trouble with, what I believe, is an inability to filter a variable node-set. 我认为我无法过滤可变节点集有麻烦。
I have a variable which is populated with a node-set from a collection of documents and I'd like to echo the input and add the variable nodes if those nodes don't already exist in the input. 我有一个变量,该变量中填充了来自文档集合的节点集,我想回显输入并添加变量节点(如果输入中不存在这些节点)。
<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>
note that there will be many instances of someInputElement with name attributes in the input. 请注意,输入中会有很多具有名称属性的someInputElement实例。
when I run the xpath //someInputElement/@name against the target I get a listing as expected. 当我对目标运行xpath // someInputElement / @ name时,得到了预期的清单。
any advice most appreciated. 任何建议,不胜感激。
I believe I've found the answer... from a hint I found somewhere else today I've added a reference back to the root and used that in the filter. 我相信我已经找到了答案...从今天在其他地方找到的提示中,我已经将引用添加回了根目录,并在过滤器中使用了该引用。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.