Hi,
and here with key.
<xsl:key name="a" match="a" use="concat(generate-id(..),'
',@type,@subtype)"/>
<xsl:template match="/">
<xsl:for-each select="doc/stuff">
<xsl:for-each
select="a[generate-id(.)=generate-id(key('a',concat(generate-id(..),'
',@type,@subtype)))]">
<xsl:sort select="@type"/>
<xsl:sort select="@subtype"/>
type(<xsl:value-of select="@type" />)
<xsl:if test="@subtype">subtype(<xsl:value-of select="@subtype"
/>) </xsl:if>
<xsl:for-each select="key('a',concat(generate-id(..),'
',@type,@subtype))">
<xsl:if test="position()!=1">,</xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:for-each>
<xsl:element name="br"/>
</xsl:for-each>
</xsl:template>
Juergen
-----Ursprüngliche Nachricht-----
Von: Jarno(_dot_)Elovirta(_at_)nokia(_dot_)com
[mailto:Jarno(_dot_)Elovirta(_at_)nokia(_dot_)com]
Gesendet am: Dienstag, 10. Juni 2003 10:12
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff: RE: [xsl] Grouping and transforming XML elements
Hi,
type(1) subtype(2): A, B, C. type(2) subtype(3): ZZ, WW. type(3): JJ.
type(1) subtype(2): AA, BB.
That is, each <stuff> is to be on a line of its own. Some
sample code would
be fantastic.
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="doc/stuff">
<xsl:if test="not(position() = 1)">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:for-each select="*[not(@type = preceding-sibling::*[1]/@type)]">
<xsl:text/>type(<xsl:value-of select="@type"/>) <xsl:text/>
<xsl:for-each select="../*[(_at_)type = current()/@type and not(@subtype
= preceding-sibling::*[1]/@subtype)]">
<xsl:choose>
<xsl:when test="@subtype">
<xsl:text/>subtype(<xsl:value-of select="@subtype"/>):
<xsl:text/>
<xsl:for-each select="../*[(_at_)type = current()/@type and
@subtype = current()/@subtype]">
<xsl:if test="not(position() = 1)">, </xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:text>. </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="../*[(_at_)type = current()/@type]">
<xsl:if test="not(position() = 1)">, </xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:text>. </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
Use keys if you need more speed.
Cheers,
Jarno - Hocico: Poltergeist
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
*****************************************************************************
Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
eMail irrtuemlich erhalten haben, informieren Sie bitte sofort den
Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren
sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.
This e-mail may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this e-mail
in error) please notify the sender immediately and destroy this e-mail.
Any unauthorized copying, disclosure or distribution of the material
in this e-mail is strictly forbidden.
*****************************************************************************
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list