Subject: Re: [xsl] XPath question concerning distinct-values() From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx> Date: Fri, 3 Aug 2012 21:31:29 +0530 |
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>
</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>
</xsl:text> </xsl:for-each> </xsl:template> On Fri, Aug 3, 2012 at 4:44 PM, Thorsten <xsl-list@xxxxxxxxxxxxx> 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 -- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XPath question concerning, Michael Kay | Thread | Re: [xsl] XPath question concerning, Thorsten |
Re: AW: [xsl] output encoding chara, Wendell Piez | Date | [xsl] Theory question about keys (n, FAIR, ED |
Month |