Subject: Re: unicity different rows
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Wed, 12 May 2004 10:45:09 -0700 (PDT)
|
Hi Lionel,
Please try the following XSL -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan">
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
<xsl:key name="by-num" match="/root/*" use="name()"/>
<xsl:key name="by-alphabet" match="/temp/*"
use="name()"/>
<xsl:template match="/root">
<xsl:for-each select="*">
<xsl:if test="generate-id(.) =
generate-id(key('by-num', name())[1])">
<xsl:element name="{name()}">
<xsl:variable name="rtf1">
<temp>
<xsl:for-each select="key('by-num', name())">
<xsl:copy-of select="child::*"/>
</xsl:for-each>
</temp>
</xsl:variable>
<xsl:variable name="rtf2">
<temp>
<xsl:for-each
select="xalan:nodeset($rtf1)/temp/*">
<xsl:if test="generate-id(.) =
generate-id(key('by-alphabet', name())[1])">
<xsl:element name="{name()}"/>
</xsl:if>
</xsl:for-each>
</temp>
</xsl:variable>
<xsl:for-each
select="xalan:nodeset($rtf2)/temp/*">
<xsl:sort select="name()" />
<xsl:element name="{name()}" />
</xsl:for-each>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<1>, <2> are not valid XML tag names.
I tested the XSL with the following XML -
<?xml version="1.0" encoding="UTF-8"?>
<root>
<one>
<a/>
<b/>
</one>
<two>
<a/>
</two>
<three>
<b/>
<c/>
</three>
<one>
<a/>
<c/>
</one>
</root>
and got the output -
<?xml version="1.0" encoding="UTF-8"?>
<one>
<a/>
<b/>
<c/>
</one>
<two>
<a/>
</two>
<three>
<b/>
<c/>
</three>
Regards,
Mukul
--- Lionel Crine <crine@xxxxxxxxxxxx> wrote:
> Hi there,
>
>
> I have a structure on which I want to make a unicity
> sort. I don't know how
> to begin.
> here it is what I have :
>
> <1>
> <a/>
> <b/>
> </1>
> <2>
> <a/>
> </2>
> <3>
> <b/>
> <c/>
> </3>
> <1>
> <a/>
> <c/>
> </1>
>
> etc ...
>
> And I want to sort the "number" by "letters" :
> Here is what I want :
>
> <1>
> <a/>
> <b/>
> <c/>
> </1>
> <2>
> <a/>
> </2>
> <3>
> <b/>
> <c/>
> </3>
>
>
> Thanks.
> Lionel
>
>
> Lionel CRINE
> Inginieur Systhmes documentaires
> Sociiti : 4DConcept
> 22 rue Etienne de Jouy 78353 JOUY EN JOSAS
> Tel : 01.34.58.70.70 Fax : 01.39.58.70.70
>
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861
|