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

RE: grouping items in a list of records

Subject: RE: grouping items in a list of records
From: "Skopik Pavel" <Pavel.Skopik@xxxxxxxxxx>
Date: Wed, 20 May 2009 15:16:19 +0200
RE:  grouping items in a list of records
Thank you very much, it works like a charm :-)

You are right, I provided wrong simple result.

Kind regards,

Pavel )kopmk

-----Original Message-----
From: Martin Honnen [mailto:Martin.Honnen@xxxxxx]
Sent: Wednesday, May 20, 2009 1:10 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  grouping items in a list of records

Skopik Pavel wrote:

> Within each "item" I need to group the node "planItemOrganization"
> according to "role" and for each role output value represented by node
> "organization/name1/name". The thing is that values of the role node
> are not constant and they may change.
> For now the stylesheets finds all roles according to key, groups
> organizations right but outputs all in the first item which is not
> desired. I am wondering how to restrict the processing to just current
> item, so that within each item groups are created in the right way. In
> XSLT 2.0 it would be fairly easy, but I am stuck with 1.0...
> This is the stylesheet which I succesfully used for grouping in one
> record now adapted to process list of records (for better readablity
> and simplification I extracted it to ouptut text):
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:key name="role" match="planItemOrganization"
> use="role/name/name"/>

If you want to restrict the grouping to the parent 'item' element then
one way to do that is to integrate the generated id of the 'item'
element into the key, as in the following stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

     <xsl:key name="role" match="planItemOrganization"
use="concat(generate-id(parent::item), '|', role/name/name)"/>

     <xsl:output method="text" encoding="UTF-8"/>
     <xsl:strip-space elements="*"/>

     <xsl:template match="data">

     <xsl:template match="datasource">

     <xsl:template match="item">
         <xsl:text>Item </xsl:text>
         <xsl:for-each select="planItemOrganization[count(. |
key('role', concat(generate-id(parent::item), '|', role/name/name))[1])
= 1]">
             <xsl:sort select="order"/>
             <xsl:value-of select="role/name/name"/>
             <xsl:for-each select="key('role',
concat(generate-id(parent::item), '|', role/name/name))">
                 <xsl:text>  </xsl:text>
                 <xsl:value-of select="organization/name1/name"/>


However that way I don't get quite the result you described, instead I get

Item 1
   Organization 1
   Organization 2
   Organization 4

   Organization 3
   Organization 5
Item 2
   Organization 5
   Organization 6

   Organization 7
   Organization 8

   Organization 9

when I run the above stylesheet against your XML sample data. The result
however should be what you want, I guess the sample result you provided
did not match the sample input data you provided.


	Martin Honnen

__________ Informace od ESET NOD32 Antivirus, verze databaze 4090 (20090520)

Tuto zpravu proveril ESET NOD32 Antivirus.


__________ Informace od ESET NOD32 Antivirus, verze databaze 4090 (20090520)

Tuto zpravu proveril ESET NOD32 Antivirus.


Current Thread


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.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
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.