Subject: Re: [xsl] A general <xsl:key> question. From: "Edward L. Knoll" <ed.knoll@xxxxxxxxxxxxxx> Date: Thu, 05 Dec 2002 16:24:13 -0700 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] A general <xsl:key> quest, Jeni Tennison | Thread | Re: [xsl] A general <xsl:key> quest, G. Ken Holman |
Re: [xsl] please help with date for, SAL ROSALES | Date | [xsl] applying templates to all chi, Ram UGroups |
Month |