[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Simple grouping with XSL2
At 2009-07-31 13:14 +1000, Andy Kohn wrote:
I'm trying to do a simple grouping and then post the siblings but I'm a little bit confused. You've got your perspective backwards by trying to address nodes in the result tree, when you must always address nodes in the source tree. I hope the example below helps. . . . . . . . . . . . Ken t:\ftemp>type andy.xml <?xml version="1.0" encoding="UTF-8"?> <Entries> <entry> <First>First Group</First> <Second>sample data I</Second> </entry> <entry> <First>Second Group</First> <Second>sample data II</Second> </entry> <entry> <First>First Group</First> <Second>sample data III</Second> </entry> </Entries> t:\ftemp>xslt2 andy.xml andy.xsl <?xml version="1.0" encoding="UTF-8"?> <Entries> <entryTransformation> <data>First Group</data> <secondaryData>sample data I</secondaryData> <secondaryData>sample data III</secondaryData> </entryTransformation> <entryTransformation> <data>Second Group</data> <secondaryData>sample data II</secondaryData> </entryTransformation> </Entries> t:\ftemp>type andy.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="/Entries"> <Entries> <xsl:for-each-group select="entry" group-by="First"> <entryTransformation> <data><xsl:value-of select="First"/></data> <xsl:for-each select="current-group()"> <secondaryData> <xsl:value-of select="Second"/> </secondaryData> </xsl:for-each> </entryTransformation> </xsl:for-each-group> </Entries> </xsl:template> </xsl:stylesheet> t:\ftemp> -- In-depth XSLT/XQuery hands-on training - Oakland/CA/USA 2009-08-03 Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|
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
|