xslt filter variable node-set using input

476 views Asked by At

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.

when I run the xpath //someInputElement/@name against the target I get a listing as expected.

any advice most appreciated.

1

There are 1 answers

1
rocketboy2000 On

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>