Dimas51
Dimas51

Reputation: 19

xslt tokenize() and "Not a node item" error

I use tokenize() function to iterate through set of values, but then I try to use this values in template calls - "Not a node item" error occurs.

        <xsl:for-each select="tokenize($edge_pairs,';')">
                <xsl:if test="number(string-length(.)) &gt; 0">
                    <xsl:variable name="c_row" select="." as="xs:string"/>
                    <xsl:variable name="src" select="substring-before($c_row,':')" as="xs:string"/>
                    <xsl:variable name="dst" select="substring-after($c_row,':')" as="xs:string"/>
                        <xsl:call-template name="links">
                            <xsl:with-param name="src1" select="$src"/>
                            <xsl:with-param name="dst1" select="$dst"/>
                        </xsl:call-template>        
                </xsl:if>
            </xsl:for-each>

this is raw that triggers error:

<xsl:for-each select="root()//gml:edge[@source = $src1 and @target = $dst1 or  @source = $dst1 and @target = $src1]">

Upvotes: 0

Views: 226

Answers (1)

Tim C
Tim C

Reputation: 70648

Assuming the code that triggers the error is in the named template links, then the issue is you are no longer in the context of the source XML document. You are inside an xsl:for-each on a tokenised string, so the context is an atomic value (i.e. a single string).

<xsl:for-each select="tokenize(a,';')">

This means the root() function will not work because the context is a string, and not a node in a document object.

The solution is define a global variable (i.e. a child of xsl:stylesheet, outside of any templates), that references the root:

<xsl:variable name="root" select="root()" />

Then you can change your xsl:for-each that is failing to this:

<xsl:for-each select="$root//gml:edge[(@source = $src1 and @target = $dst1) or (@source = $dst1 and @target = $src1)]">

Upvotes: 4

Related Questions