[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Error: XPTY0020: Leading '/' cannot select the roo

Subject: Re: Error: XPTY0020: Leading '/' cannot select the root node of the tree containing the context item: the context item is an atomic value
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Mon, 10 Jan 2011 11:44:06 +0000
Re:  Error: XPTY0020: Leading '/' cannot select the roo
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)


--
Andrew Welch
http://andrewjwelch.com

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.