2 messages in net.sourceforge.lists.saxon-helpRE: [saxon] Bug in 8.1? Cannot select...
FromSent OnAttachments
Sal ManganoNov 13, 2004 10:24 pm 
Michael KayNov 14, 2004 5:55 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:RE: [saxon] Bug in 8.1? Cannot select a node here: the context item is an atomic value.Actions
From:Michael Kay (mh@mhk.me.uk)
Date:Nov 14, 2004 5:55:40 am
List:net.sourceforge.lists.saxon-help

The line number is a known problem which I haven't got round to solving yet. If you need to know, the real line number is in the low-order 16 bits.

The rest of the error message is correct. The key() function searches for nodes in the current document, i.e. the document containing the context node, and if there isn't a context node, then it doesn't know which document you want to search.

-----Original Message----- From: saxo@lists.sourceforge.net [mailto:saxo@lists.sourceforge.net] On Behalf Of Sal Mangano Sent: 13 November 2004 21:07 To: saxo@lists.sourceforge.net Subject: [saxon] Bug in 8.1? Cannot select a node here: the context item is an atomic value.

Here is a fragment of an XSLT transform I am writing to parse some unstructured text:

<xsl:when test="string-length($input) &lt; 50 and matches($input,'^By [\w\s.,]+ and [\w\s.]+$')"> <xsl:variable name="author" select="tokenize($input,'(and|,)','i')" as="xs:string*"/> <art:ByLine> <xsl:for-each select="$author"> <xsl:variable name="name" select="if (position() = 1) then substring(.,3) else ." as="xs:string"/>

<!--THIS LINE CAUSES THE ERROR MESSAGE --> <xsl:variable name="email" select="if (key('AuthorKey',$name)) then key('AuthorKey',$name)/email else 'webm@somewhere.com'" as="xs:string"/>

<art:Author> <art:name><xsl:value-of select="$name"/></art:name> <art:email><xsl:value-of select="$email"/></art:email> </art:Author> </xsl:for-each> </art:ByLine> </xsl:when>

The line indicated causes the following error:

Error on line 1048575 Cannot select a node here: the context item is an atomic value.

Now, at the very least, the line number is bogus because this XSLT file only has 202 lines. Second, I am not sure why I can't set a variable using key() just because the Context node is atomic. The problem seems related to the use of key() because if I remove key() and replace with some dummy expression the error goes away.

Use XSLT? Try the XSLT Cookbook http://www.oreilly.com/catalog/xsltckbk/