[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT Grouping


xslt grouping table
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


  • References:

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.