使用输入筛选变量节点集的xslt
我认为,我遇到的问题是无法过滤可变节点集 我有一个变量,该变量由一组文档中的节点集填充,如果这些节点在输入中不存在,我希望回显输入并添加变量节点使用输入筛选变量节点集的xslt,xslt,filter,node-set,Xslt,Filter,Node Set,我认为,我遇到的问题是无法过滤可变节点集 我有一个变量,该变量由一组文档中的节点集填充,如果这些节点在输入中不存在,我希望回显输入并添加变量节点 <xsl:variable name="views" select="collection('file:/C:/temp/?select=*.xml;recurse=yes')"/> <xsl:template match="node()|@*"> <xsl:copy> <xs
<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>
请注意,输入中会有许多具有name属性的someInputElement实例
<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>
当我针对目标运行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>
IMHO,一个(小的)可复制的例子会很有用。事实上,我们看不到变量中有什么,也看不到输入中有什么。我希望能深入了解过滤器,以及它是否是一种有效的方法。它无法从$views变量中筛选所选内容。我在问题中补充了一点,即在输入中会有许多带有名称属性的输入实例。为了提高效率,您可以添加一个键
,然后只需使用$views/someElement[not(key('by-name',@name,$root))]
。