xsl-list
[Top] [All Lists]

Re: [xsl] Error: XPTY0020: Leading '/' cannot select the root node of the tree containing the context item: the context item is an atomic value

2011-01-10 06:34:37
Hello Michael, Martin, and Andrew,

Thanks to your help it works perfectly now!

I am impressed: less than ten minutes later three perfect answers :)

Thank you very much, 

Dietrich


On Mon, 2011-01-10 at 11:44 +0000, Andrew Welch wrote:
Hi,

You get this error:

Error on line 12 of example-b.xsl:
 XPTY0020: Leading '/' cannot select the root node of the tree
containing the context item:
 the context item is an atomic value

...because here within the for-each the "context item" is each of the
items in the sequence of tokenized values (strings):

     <xsl:for-each select="tokenize(example/bar/@ids, ',')">
       <xsl:value-of select="."/>: <xsl:value-of
select="key('index', .)" />

When you make the key call, it must be applied to an input tree...
which by default is the tree containing the context node.  As there is
no context node here, it causes the error.  The solution is to store a
reference to the input doc outside of the for-each (say as a top-level
element), and then reference that in the key:

<xsl:variable name="input" select="."/>

with

key('index', ., $input)






--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--