[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT Grouping
At 2005-12-16 18:21 +0530, Bisht Anand wrote: >I'm bit new to xslt world, XSLT and XPath questions would be better posted to the following list: http://www.mulberrytech.com/xsl/xsl-list There are a number of subscribers who would enthusiastically respond to such questions. There is also an *excellent* XSLT FAQ at: http://www.dpawson.co.uk >could anyone help me to associate the child parent relationship in grouping See http://www.jenitennison.com/xslt/grouping for guidance. >as an example of xml file to group using of xslt. I hope the example below helps. . . . . . . . . . . Ken T:\ftemp>type singh.xml <root> <table> <id>1</id> <parentid>0</parentid> <title>Test1</title> <desc></desc> </table> <table> <id>2</id> <parentid>1</parentid> <title>Test1</title> <desc></desc> </table> <table> <id>3</id> <parentid>1</parentid> <title>Test1</title> <desc></desc> </table> <table> <id>4</id> <parentid>3</parentid> <title>Test1</title> <desc></desc> </table> <table> <id>10</id> <parentid>3</parentid> <title>Test1</title> <desc></desc> </table> </root> T:\ftemp>type singh.xsl <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:key name="parents" match="table" use="parentid"/> <xsl:template match="/"> <xsl:for-each select="/*/table[generate-id(.)= generate-id(key('parents',parentid)[1])]"> <xsl:text/>Parent <xsl:value-of select="parentid"/>: <xsl:text/> <xsl:for-each select="key('parents',parentid)"> <xsl:if test="position()>1">,</xsl:if> <xsl:value-of select="id"/> </xsl:for-each> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet> T:\ftemp>xslt singh.xml singh.xsl con Parent 0: 1 Parent 1: 2,3 Parent 3: 4,10 T:\ftemp> -- Upcoming XSLT/XSL-FO hands-on courses: Denver,CO March 13-17,2006 World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@C... Crane Softwrights Ltd. http://www.CraneSoftwrights.com/x/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/x/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
|