OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] XSLT Grouping

[ Lists Home | Date Index | Thread Index ]

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@CraneSoftwrights.com
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


  • References:



 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS