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

RE: key() and document() - scoping problem?

Subject: RE: key() and document() - scoping problem?
From: "Bryn Lewis" <blewis@xxxxxxxxxx>
Date: Wed, 20 Dec 2006 09:56:43 +1100
bryn lewis
ok, I now understand the problem, but not the solution. What I actually want
is this:

<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', .))" />
        </span>
</xsl:for-each>

to produce this:
<span class="x">4</span>
<span class="y">4</span>

and not:
<span class="x">4</span>
<span class="y">0</span>

That is, each of the options/option values is an index into the key. I don't
want to have to specify what each of them is.

If I change the context node I don't have the value to look up.  ?

Bryn

-----Original Message-----
From: Andrew Welch [mailto:andrew.j.welch@xxxxxxxxx]
Sent: Tuesday, 19 December 2006 8:56 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  key() and document() - scoping problem?

On 12/19/06, Bryn Lewis <blewis@xxxxxxxxxx> wrote:
> 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.

Why?  The key is used on the document that the context node belongs to, so you
are seeing the results from two different documents.

In this case to get the same result inside that for-each as outside it you can
either:

- store the result of the call to key() in a variable and use that
- store a pointer to the original source document and switch back to it before
calling key(), either by using another for-each in XSLT 1.0 or the third
argument to key() in XSLT 2.0

cheers
andrew


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.24/592 - Release Date: 18/12/2006
1:45 PM


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.25/593 - Release Date: 19/12/2006
1:17 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

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.