Project

Profile

Help

Error "context item is undefined"

Added by Anonymous over 15 years ago

Legacy ID: #6645311 Legacy Poster: Frank Ploessel (fploessel)

Hi, The following stylesheet gives error "XPDY0002: Cannot select a node here: the context item is undefined" in Saxon 9.1.0.5J. I understand that a function does not have a context node. But as the path is absolute, the loop range should be clear here. <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://www.blahblah.org/demo"> <xsl:function name="t:show-bug"> <xsl:sequence select="for $i in /a/b/c return $i" /> </xsl:function> </xsl:stylesheet> Frank


Replies (2)

RE: Error &quot;context item is undefined&quot; - Added by Anonymous over 15 years ago

Legacy ID: #6645486 Legacy Poster: Michael Kay (mhkay)

The term "absolute" is misleading (and is no longer used in the XPath specification). A path starting with "/" selects relative to the root of the document that contains the context node. So if we don't know the context node, we don't know which document to search. You need to pass the relevant document node as a parameter; or if the stylesheet is only handling one document, you can bind it to a global variable: <xsl:variable name="root" select="/"> <xsl:function... <xsl:sequence select="$root/a/b/c" Michael Kay http://www.saxonica.com/

RE: Error &quot;context item is undefined&quot; - Added by Anonymous over 15 years ago

Legacy ID: #6646065 Legacy Poster: Frank Ploessel (fploessel)

Michael, Thank you for the quick answer. Your approach solves the issue. Frank

    (1-2/2)

    Please register to reply