0

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.

rocketboy2000
  • 119
  • 1
  • 11
  • A (small) reproducible example would be useful, IMHO. As it is, we can't see what's in your variable nor what's in the input. – michael.hor257k Nov 29 '14 at 04:51
  • I'm hoping for some insight into the filter and whether its a valid approach. it fails to filter selection from the $views variable. I've added to my question that there will be many instances of someImputElement with name attributes in the input. – rocketboy2000 Nov 29 '14 at 06:09

1 Answers1

0

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>
rocketboy2000
  • 119
  • 1
  • 11