|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Grouping Using XSL
So you want to group the data elements by their col 1 and col 2 values.
You must concatenate those values for it:
<xsl:key name="data" match="data" use="concat(col[@id='1'], '::', col[@id='2'])"/> Now you can apply-templates on group-starters: <xsl:template match="/*"> <xsl:copy> <xsl:apply-templates select="data[generate-id() = generate-id(key('data', concat(col[@id='1'], '::', col[@id='2'])))]" mode="unique"/> </xsl:copy> </xsl:template> They are copied to the output and create a "container" col 3 element for the val elements. The next step is applying templates to all the data elements with the same concatenated string of col 1 and col2: <xsl:template match="data" mode="unique"> <xsl:copy> <xsl:copy-of select="col[@id='1' or @id='2']"/> <col id="3"> <xsl:apply-templates select="key('data', concat(col[@id='1'], '::', col[@id='2'])" mode="col3"/> </col> </xsl:copy> </xsl:template> The val elements: <xsl:template match="data" mode="col3">
<val>
<xsl:value-of select="col[@id='3']"/>
</val>
</xsl:template>The technique is called Muenchian Grouping and the default recommended page for it is http://www.jenitennison.com/xslt/grouping/muenchian.xml. <xsl:for-each-group/> seems to be XSLT 2.0. The spec is only a working draft and not a recommendation. So there can still change some things. The Xalan group starts to implement it, another implementation is Saxon 7.x. But using the above with an XSLT 1.0 processor is more recommended at the moment I think. Regards, Joerg Rigoberto wrote: hi everybody!!! XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








