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

Re: [xsl] XPath question concerning distinct-values()


Subject: Re: [xsl] XPath question concerning distinct-values()
From: Thorsten <xsl-list@xxxxxxxxxxxxx>
Date: Wed, 8 Aug 2012 10:36:40 +0200 (CEST)

Hello Michael,
hello Mukul,

I've used Michael's suggestion, cause it seems to be the simplest way to do
this, as he wrote too.

Michael Kay <mike@xxxxxxxxxxxx> hat am 3. August 2012 um 15:20 geschrieben:>
It's simplest to use xsl:for-each-group for this.
>
> <xsl:template match="pricelist">
> <xsl:for-each-group select="item" group-by="order-number">
> <xsl:value-of select="current-group()[1]/(order-number, price),
> '&#xa;'"/>
> </xsl:for-each-group>
> </xsl:template>
>
>
> Michael Kay
> Saxonica
>

Mukul, your solutions are really interessting! Thank you too. Maybe I can use
something like that somewhen!
(Well, never ever used <xsl:key> before...)


Mukul Gandhi <gandhi.mukul@xxxxxxxxx> hat am 3. August 2012 um 18:01
geschrieben:> Hi Thorsten,
> Here are few more 2.0 approaches (hopefully, would meet your
> requirement) to solve this problem:
>
> 1)
>
> <xsl:template match="/">
> <xsl:variable name="unique-order-nums"
> select="distinct-values(pricelist/item/order-number)"/>
> <xsl:variable name="docRoot" select="/"/>
> <xsl:for-each select="$unique-order-nums">
> <xsl:value-of select="current()"/><xsl:text>
> </xsl:text><xsl:value-of select="$docRoot/pricelist/item[order-number
> = current()][1]/price"/><xsl:text>&#xA;</xsl:text>
> </xsl:for-each>
> </xsl:template>
>
>
> 2)
>
> <xsl:key name="item-key" match="item" use="order-number"/>
>
> <xsl:template match="/">
> <xsl:variable name="unique-order-nums"
> select="distinct-values(pricelist/item/order-number)"/>
> <xsl:variable name="docRoot" select="/"/>
> <xsl:for-each select="$unique-order-nums">
> <xsl:value-of select="current()"/><xsl:text>
> </xsl:text><xsl:value-of select="key('item-key', current(),
> $docRoot)[1]/price"/><xsl:text>&#xA;</xsl:text>
> </xsl:for-each>
> </xsl:template>
>
> Regards,
> Mukul Gandhi
>

Regards,
Thorsten


Current Thread