簡體   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