[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] key() and document() - scoping problem?


Subject: RE: [xsl] key() and document() - scoping problem?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 19 Dec 2006 10:30:44 -0000

The key() function searches the document that contains the context node.

In 1.0, you need to change the context node, which you can do using
xsl:for-each.

In 2.0, you can use the third argument of key() to determine which document
is searched.

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

> -----Original Message-----
> From: Bryn Lewis [mailto:blewis@xxxxxxxxxx] 
> Sent: 19 December 2006 08:16
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] key() and document() - scoping problem?
> 
> I have defined a key, then use its value in the following xsl 
> (xslt v.1):
> 
> <span class="x">
> 	<xsl:value-of select="count(key('key2_1', 'general'))" 
> /> </span> <xsl:for-each 
> select="document(string($options))/options/option">
> 	<span class="y">
> 		<xsl:value-of select="count(key('key2_1', 
> 'general'))" />
>     	</span>
> </xsl:for-each>
> 
> Results in this:
> 
> <span class="x">4</span>
> <span class="y">0</span>
> 
> I would expect to get a '4' in both cases.
> 
> The document referred to is referenced correctly and I would 
> be using it to specify the key value required.
> 
> The document seems to throw the key out of scope, but I dont 
> see how to correct that.
> 
> thanks, Bryn
> 
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.432 / Virus Database: 268.15.24/592 - Release 
> Date: 18/12/2006 1:45 PM
>  
> The contents of this email and any attachments are 
> confidential and may be privileged or otherwise protected 
> from disclosure.
> 
> If you are not the intended recipient of this email please 
> notify the sender immediately, delete the email and any 
> attachments from your system and do not print, distribute, 
> store, commercialise or act on any information it contains.


Current Thread
Keywords
xsl