繁体   English   中英

使用输入的xslt过滤器变量节点集

[英]xslt filter variable node-set using 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>

请注意,输入中会有很多具有名称属性的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM