Re: [xsl] find position of first occurrence in a node set

Subject: Re: [xsl] find position of first occurrence in a node set
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 2 Aug 2005 22:40:06 +0100
> 2)  As you can see I'm having to copy in the current-group() to a 
> variable before I can apply the <xsl:number> instruction.  I tried this:

That's a postentially expensive way of getting the right number, as
copying a tree is a relatively expensive oeration.


>     <xsl:number select="current-group[@type='HL'][1]"/>
> 
> But the value I get in return is wrong.  It seems to be counting the 
> attributes as well as the <segment> elements. 

No, it's just counting elements but it is counting all elements based on
the document structure (not just those in the current group) Your actual
posted question didn't involve groping and

<xsl:stylesheet version="2.0"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method = "html" omit-xml-declaration="yes" />

<xsl:template match="/">
 <xsl:number select="*/segment[@type='HL'][1]"/>
</xsl:template>
</xsl:stylesheet>

returns 3. If you are grouping as well then you'll need to restrict the
numbering to your group. Copying the group to another tree os one way,
as you found, but there may be more efficient ways eg using xsl:number's
from attribute, but it depends....

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread