[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] xsl:number and including nodes with xsl:key


Subject: RE: [xsl] xsl:number and including nodes with xsl:key
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 29 Aug 2003 09:11:13 +0100

<xsl:number> gives you a number based on the position of the current
node within the tree that it's part of. It's not affected by the
processing that led you to that node.

If your processing of <insert> elements is fully recursive, then I think
the best solution is the same as recommended to another poster earlier
this week: do two phases, one to create the nodes in the result tree,
the second to number them.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Denis Haskin
> Sent: 29 August 2003 04:03
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] xsl:number and including nodes with xsl:key
> 
> 
> I sincerely apologize if this is a FAQ; I'm unable to find an 
> answer to 
> this in the archives nor the FAQ (although there are a couple of FAQ 
> entries that are similar to this and imply to me that what I'm doing 
> should work).
> 
> I am using xsl:key and select="key()" to include part of my 
> input tree 
> at another place during processing.  This works fine, but the 
> problem is 
> I'm trying to using xsl:number as well and I can't prevent xsl:number 
> from resetting (apparently) its context while processing the 
> referred-to 
> nodes.  (Apologies if my terminology is not correct; I'm back to XSL 
> after having not used it much in the last year-plus.)
> 
> Here's a *very* simplified example.  Here's my input XML:
> 
> <test>
> <extra myid="extraid"><name>Extra item</name></extra>
> <item>
>  <name>Item one</name>
>  <name>Item two</name>
>  <name>Item three</name>
>  <insert ref="extraid"/>
> </item>
> </test>
> 
> 
> and I'm processing it with this XSL:
> 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <xsl:stylesheet 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> 
> <xsl:key name="testkey" match="extra" use="@myid"/>
> 
> <xsl:template match="insert">
>   <xsl:variable name="d" select="key('testkey',@ref)"/>
>   <xsl:apply-templates select="$d" mode="include"/> </xsl:template>
> 
> <xsl:template match="name">
>   <xsl:number/> - <xsl:value-of select="."/>
> </xsl:template>
> 
> <xsl:template match="extra" mode="include">
>   <xsl:apply-templates/>
> </xsl:template>
> 
> <xsl:template match="extra"/>
> 
> </xsl:stylesheet>
> 
> what I'm getting for output is this:
> 
>   1 - Item one
>   2 - Item two
>   3 - Item three
>   1 - Extra item
> 
> and what I want is:
> 
>   1 - Item one
>   2 - Item two
>   3 - Item three
>   4 - Extra item
> 
> Is this possible?  I've messed a bunch with level, from, 
> count, etc without any luck.  I feel like this should be a 
> no-brainer...
> 
> Much thanks --
> 
> dwh
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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



Current Thread
Keywords
xsl