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

RE: Key error: the context item is undefined

Subject: RE: Key error: the context item is undefined
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 12 Dec 2005 19:17:18 -0000
xpdy0002
I imagine you want to search within the document that contains the $obj
node. In this case you can write

<xsl:value-of select="foo:do.it(key('by.id', $obj/@idref, $obj/root()))"/>

or if you prefer,

<xsl:value-of select="foo:do.it($obj/key('by.id', @idref))"/>

The reason for the error is that key(), with 2 arguments, always searches
the document containing the context node, and if there isn't a context node
then it doesn't know which document to search.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: drkm [mailto:darkman_spam@xxxxxxxx]
> Sent: 12 December 2005 18:45
> To: XSL Mulberry list
> Subject:  Key error: the context item is undefined
>
>   Hi
>
>   I have a problem using a key.  I have an XPath function
> that can deal with elements that are identifiers for other
> elements.  In such a case, the function uses a key to
> retreive the effective element (corresponding to the id).
>
>   Saxon-SA 8.6.1 give me the following error message:
>
>     Error on line 13 of ~/drafts/key-wo-context.xsl:
>       XPDY0002: Cannot select a node here: the context item
>       is undefined
>
>   While I think I understand mostly what it means, I can't
> find a way to do what I want.  Below is a minimal example
> that reproduce the error:
>
>     ~/drafts $ cat key-wo-context.xsl
>     <xsl:transform
>         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>         xmlns:foo="..."
>         version="2.0">
>
>       <xsl:output method="text"/>
>
>       <xsl:key name="by.id" match="item" use="id"/>
>
>       <xsl:function name="foo:do.it">
>         <xsl:param name="obj"/>
>         <xsl:choose>
>           <xsl:when test="$obj/@idref">
>             <xsl:value-of
>                 select="foo:do.it(key('by.id', $obj/@idref))"/>
>           </xsl:when>
>           <xsl:otherwise>
>             <xsl:value-of select="."/>
>           </xsl:otherwise>
>         </xsl:choose>
>       </xsl:function>
>
>       <xsl:template match="/">
>         <xsl:value-of select="*[1]/*"/>
>       </xsl:template>
>
>     </xsl:transform>
>
>     ~/drafts $ cat key-wo-context.xml
>     <root>
>       <item id="a">A</item>
>       <item id="b">B</item>
>       <item idref="b"/>
>       <item id="c">C</item>
>       <item idref="c"/>
>       <item idref="a"/>
>       <item id="d">D</item>
>     </root>
>
>     ~/drafts $ saxon key-wo-context.xml key-wo-context.xsl
>     Error on line 13 of ~/drafts/key-wo-context.xsl:
>       XPDY0002: Cannot select a node here: the context item
>       is undefined
>     Failed to compile stylesheet. 1 error detected.
>
>   Do you have any idea?
>
>   Thanks,
>
> --drkm
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ______________________________________________________________
> _____________
> Appel audio GRATUIT partout dans le monde avec le nouveau
> Yahoo! Messenger
> Tilichargez cette version sur http://fr.messenger.yahoo.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.