This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RE: Re: Converting the flat XML to hierarchical format (plus grouping, data replication and sorting)


add <xsl:sort> after <xsl:for-each>: http://www.w3.org/TR/xslt#sorting

Regards,

Joerg

----- Original Message -----
From: "Shyam Chebrolu" <schebrolu@webtonetech.com>
To: <XSL-List@lists.mulberrytech.com>
Sent: Wednesday, January 30, 2002 8:01 PM
Subject: [xsl] RE: Re: Converting the flat XML to hierarchical format (plus
grouping, data replication and sorting)


> I tried to post this before. It was bounced back for some reason...
>
> Anyway, I was able to comeup with some solution. But it is not complete.
>
> I couldn't figure out how to sort the items after they are grouped...
>
> I used the below XSL:
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> version="1.0">
>
> <xsl:key name="products-by-group" match="GROUP_ID" use="." />
> <xsl:variable name="product-id" select="DATA/PRODUCT_ID" />
> <xsl:variable name="product-desc" select="DATA/PRODUCT_DESC"/>
> <xsl:variable name="group-id" select="DATA/GROUP_ID"/>
>
> <xsl:template match="/">
> <DATA>
> <xsl:for-each select="DATA/GROUP_ID[count(. |
> key('products-by-group', .)[1]) = 1]">
> <PRODUCTS>
> <xsl:attribute name="ID"><xsl:value-of  select="."
> /></xsl:attribute>
> <xsl:variable name="n" select="." />
>
> <xsl:for-each select="$group-id[. = $n or . = 0]">
> <xsl:variable name="index"
> select="count(preceding-sibling::GROUP_ID) + 1" />
> <PRODUCT>
> <xsl:copy-of
> select="$product-id[$index]" />
>   <xsl:copy-of
> select="$product-desc[$index]" />
> </PRODUCT>
> </xsl:for-each>
> </PRODUCTS>
> </xsl:for-each>
> </DATA>
> </xsl:template>
> </xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]