xsl-list
[Top] [All Lists]

xsl:number and including nodes with xsl:key

2003-08-28 20:02:40
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