|
Subject: Re: [xsl] Adjusting sorted list From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 16 May 2002 16:35:55 +0100 |
Andrew Timberlake wrote:
> I have the following XML:
> <a>
> <b>4</b>
> <b>9</b>
> <b>6</b>
> <b>1</b>
> <b>8</b>
> <b>6</b>
> <b>4</b>
> <b>7</b>
> </a>
>
> I am trying to generate the following ouput:
> <a>
> <b rank="1">1</b>
> <b rank="2">4</b>
> <b rank="2">4</b>
> <b rank="3">6</b>
> <b rank="3">6</b>
> <b rank="4">7</b>
> <b rank="5">8</b>
> <b rank="6">9</b>
> </a>
For interest, the XSLT 2.0 version would be:
<xsl:template match="a">
<a>
<xsl:for-each-group select="b" group-by="." />
<xsl:sort select="." />
<xsl:variable name="rank" select="position()" />
<xsl:for-each select="current-group()">
<b rank="{$rank}">
<xsl:value-of select="." />
</b>
</xsl:for-each>
</xsl:for-each-group>
</a>
</xsl:template>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Adjusting sorted list, Andrew Timberlake | Thread | RE: [xsl] Adjusting sorted list, TSchutzerWeissmann |
| [xsl] Re: Confused about "/.." patt, Dimitre Novatchev | Date | Re: [xsl] Confused about "/.." patt, Joerg Heinicke |
| Month |