Subject: Re: [xsl] grouping with xslt 1.0 From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Wed, 23 Sep 2009 12:10:35 +0200 |
Here is my input:
<data> <product id="1"> <seta numer="5"> ... </seta> <seta number="9"> <element> <name>A</name> <properties>...</properties> </element> </seta> <setc>....</setc> </product> <product id="2"> <seta numer="5"> ... </seta> <seta number="9"> <element> <name>B</name> <properties>...</properties> </element> </seta> <setc>....</setc> </product> <product id="3"> <seta numer="5"> ... </seta> <seta number=9> <element> <name>A</name> <properties>...</properties> </element> </seta> <setc>....</setc> </product> </data>
There are three "product" elements which hold "seta" and "setc" tags. Within the "seta" tag there is a name by which the products should be grouped. All products with the same name hold the same "seta" elements but different "setc" elements. So I want to create for both "product" elements with the same name (A) a new element "konto" with attribute "name=A". The konto element holds the "seta" elements which are identical or "A" and "B" and the two(!) "setc" elements. One setc from A and one from B.
The result should look like this: <data> <konto name="A"> <seta number="5"> ... </seta> <seta number=9> <element> <name>A</name> <properties>...</properties> </element> </seta> <setc>...</setc> <setc>...</setc> </konto> <konto name="B"> <seta numer="5"> ... </seta> <seta number=9> <element> <name>B</name> <properties>...</properties> </element> </seta> <setc>....</setc> </konto> </data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*"/> <xsl:output indent="yes"/>
<xsl:template match="product"> <konto name="{seta/element/name}"> <xsl:copy-of select="seta"/> <xsl:copy-of select="key('k1', seta/element/name)/setc"/> </konto> </xsl:template>
</xsl:stylesheet> --
Martin Honnen http://msmvps.com/blogs/martin_honnen/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] grouping with xslt 1.0, Garvin Riensche | Thread | [xsl] References to elements in pre, rowan@xxxxxxxxxxxxxx |
[xsl] grouping with xslt 1.0, Garvin Riensche | Date | [xsl] References to elements in pre, rowan@xxxxxxxxxxxxxx |
Month |