Subject: Re: [xsl] how to get position of node in node-set From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 11 Sep 2003 13:20:08 -0400 |
Node sets are sets and so don't have an intrinsic order. So nodes don't really have a position in a set (you can't for example sort the nodes and save the sorted list in a set)
<xsl:variable name="legend" select="//entry[count(.|key('entries-by-text',@text)[1])=1]"/>
<xsl:variable name="legend"> <xsl:apply-templates select="//entry" mode="de-duplicate"> <xsl:sort select="@text"/> </xsl:apply-templates> </xsl:variable>
You can ask what is the position if the nodes in the set were sorted into document order, although actually it's not so easy. If the nodes are siblings and you are on <entry text="ccc"/> then you want count(preceding-sibling::entry)+1 however you only want to count nodes that are in $legend so that would be count(preceding-sibling::entry[@text=$legend])+1
if your text attribute uniquely determines the node,
or something like count(preceding-sibling::entry[count(.|$legend)=count($legend)]+1 otherwise.
They are all pure xpath solutions, or you could use xsl, as in
<xsl:for-each select="$legend"> <xsl:if test="@text='ccc'"><xsl:value-of select="position()"/></xsl:if>
<xsl:template match="entry"/> <xsl:variable name="text" select="@text"/> <xsl:for-each select="$legend"> <xsl:sort select="@text"/> <xsl:if test="@text=$text"> <xsl:value-of select="position()"/> </xsl:if> </xsl:for-each> </xsl:template>
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] how to get position of no, David Carlisle | Thread | [xsl] How to split table colums ove, Barry van Weldam |
[xsl] preceding-sibling after sort , Kaine Varley | Date | [xsl] How to split table colums ove, Barry van Weldam |
Month |