[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: Michael Kay <mike@xxxxxxxxxxxx>
Date: Fri, 03 Aug 2012 14:20:39 +0100

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


On 03/08/2012 12:14, Thorsten wrote:
Hello,

I have a terrible SAP export that looks (simplified) like this:

<pricelist>
    <item>
       <title>Lorem Ipsum Dolor Sit Amet</title>
       <order-number>XY7020280901</order-number>
       <price>12.00</price>
       <unit>50</unit>
    </item>
    <item>
       <title>Some Title</title>
       <order-number>XY9010200901</order-number>
       <price>19.00</price>
       <unit>50</unit>
    </item>
    <item>
       <title>The Same Item With A Different Title</title>
       <order-number>XY9010200901</order-number>
       <price>19.00</price>
       <unit>50</unit>
    </item>
    <item>
       <title>Lorem Ipsum Dolor</title>
       <order-number>XY7010220201</order-number>
       <price>18.00</price>
       <unit>50</unit>
    </item>
</pricelist>

I want to select each <item> with different <order-number>. Simply
distinct-values(/pricelist/item) doesn't work because the <title> of item[2] and
item[3] are different.

My output should look like this:
XY7020280901  12.00
XY9010200901  19.00
XY7010220201  18.00

I'm using XSLT2.0 with Saxon 9.2 PE.

Any ideas?

Many thanks in advance.

Kind regards
Thorsten


Current Thread