Project

Profile

Help

Context item undefined in function error

Added by Anonymous almost 19 years ago

Legacy ID: #3227479 Legacy Poster: DD (ddevienne)

Why is Saxon 8.4 failing with: :40: Fatal Error! Cannot select a node here: the context item is undefined, when line 40 is the definition of the teams var below: <xsl:function name="my:users" as="node()*"> <xsl:param name="from" as="node()" /> <xsl:variable name="team-refs" select="$from/team-ref/@name" /> <xsl:variable name="teams" select="key('teams', $team-refs)" /> ... </xsl:function> I don't understand what depends on the context item, since all nodes are rooted at $from. Thanks for any insight. --DD


Replies (3)

Please register to reply

RE: Context item undefined in function error - Added by Anonymous almost 19 years ago

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

The key() function selects nodes within the current document - that is, the document containing the context node. If there's no context node then it doesn't know which document to search. Write $from/key('teams', $team-refs). Michael Kay

RE: Context item undefined in function error - Added by Anonymous almost 19 years ago

Legacy ID: #3227652 Legacy Poster: DD (ddevienne)

Thanks a bunch. Sounds logical now that you mention it, and explains why <xsl:key> doesn't require a full xpath in its match attribute. I was mistakenly drawing a parallel between a global var and a key (also defined at the top-level). BTW, I ran again into the 'Unknown value representation' bug. May I ask if you're considering a 8.5 release soon? Thanks, --DD PS: Did I miss the $from/key() in a function example in your book? Or is it just too much a corner case to document? I fully understand one can't put everything in a book. No complaints, just wondering ;-) PPS: I worked around the issue by using a named template, but I'll switch to a function to make it easily recursive.

RE: Context item undefined in function error - Added by Anonymous almost 19 years ago

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

I've blocked out a week in my diary during July and hope this will be sufficient to get 8.5 out of the door. I can't immediately spot this example in the book. You can also specify the document to be searched by using the 3rd argument of key(), which is described in the book - note however that the meaning of this argument has changed slightly since the book was published - if you supply an element, then the function will only search the subtree rooted at that element, not the whole document containing that element. MK

    (1-3/3)

    Please register to reply