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.
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.