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

Subject: RE: [xsl] key() and document() - scoping problem?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 19 Dec 2006 18:43:57 -0500
Bryn,

At 05:56 PM 12/19/2006, you wrote:
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.

It looks to me as though you want:


<span class="x">
  <xsl:value-of select="count(key('key2_1', 'general'))" />
</span>
<xsl:variable name="option-keys"
  select="document(string($options))/options/option">
<span class="y">
  <xsl:value-of select="count(key('key2_1', $option-keys))" />
</span>

Or something of that sort.

It happens that keys can also take node sets as arguments to provide multiple values at once. As you can see, this can be useful. (I use a variable for clarity but you could just throw the document() query straight into the call to key() if you wanted.)

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread