Re: [xsl] A general <xsl:key> question.

Subject: Re: [xsl] A general <xsl:key> question.
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 5 Dec 2002 17:11:49 +0000
Hi Edward,

> Do keys have to be used within a context in which the associated
> nodes exist?

Yes. The context node at the point where you use the key (with the
key() function) has to be a node in the document that you're
searching.

Usually this means that you should create a variable to hold the key
value that you want to search for, then switch into the context of the
document that you want to search in (using <xsl:for-each>) before
using the key.

I can't tell precisely what's going to work with your code, but
something like:

<xsl:key name="PageKey" match="/gnsl:Results/gnsl:Table/gnsl:Row"
         use="((count(preceding-sibling::*) div $RowsPerPage) + 1)" />

<xsl:variable name="results" select="/" />

<xsl:template name="ProcessPageRows">
   <xsl:variable name="PageNum" select="@PageNum" />
   <xsl:variable name="StartRow" select="@StartRow" />
   <xsl:variable name="EndRow" select="@EndRow" />

   <xsl:if test="$NumberOfRows">
      <xsl:for-each select="$results">
        <xsl:apply-templates select="key('PageKey',$PageNum)" />
      </xsl:for-each>
   </xsl:if>
</xsl:template>

You need to set the $results variable to being a node set containing a
single node in the document in which the gnsl:Row elements that you're
interested in are held.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread