0

我遇到了麻烦,我相信,无法过滤变量节点集。

我有一个变量,其中填充了来自文档集合的节点集,如果输入中不存在这些节点,我想回显输入并添加变量节点。

<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 实例。

当我针对目标运行 xpath //someInputElement/@name 时,我得到了预期的列表。

任何建议最受赞赏。

4

1 回答 1

0

我相信我已经找到了答案……根据我今天在其他地方找到的提示,我添加了对根的引用并在过滤器中使用了它。

<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>
于 2014-11-29T06:45:01.153 回答