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

Re: A general <xsl:key> question.

Subject: Re: A general <xsl:key> question.
From: "Edward L. Knoll" <ed.knoll@xxxxxxxxxxxxxx>
Date: Thu, 05 Dec 2002 16:24:13 -0700
edward knoll
Jeni Tennison wrote:
> 
> 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.
> 
> Jeni Tennison
> http://www.jenitennison.com/

Worked, have to do the performance test to see what I gained.  Had to
adjust the syntax a bit; (forcing the key to be an integer helped a
bunch):

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

<xsl:template name="ProcessPageRows">
   <xsl:variable name="PageNum" select="@PageNum" />
   <xsl:if test="$NumberOfRows">
      <xsl:for-each select="$Results">
      <xsl:for-each select="key('PageKey',$PageNum)">

         <xsl:apply-templates select="." />

      </xsl:for-each>
      </xsl:for-each>
   </xsl:if>
</xsl:template>

Thanks for the help,
Ed

-- 
Edward L. Knoll   Phone (work)     : (719)484-2717
                  e-mail (work)    : ed.knoll@xxxxxxxxxxxxxx
                  e-mail (business): eknoll@xxxxxxxxxx
                  e-mail (personal): edward@xxxxxxxxxxx

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


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.