Altova Mailing List Archives
>xsl-list Archive Home
>Thread Prev - [xsl] key() and document() - scoping problem?
>Thread Next - RE: [xsl] key() and document() - scoping problem?
Re: [xsl] key() and document() - scoping problem?
Date: 12/19/2006 9:56:00 AM
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