Dear Jeni, dear all others helping me with this problem.
Yesterday night, already in bed, I suddenly remembered having seen an
article a few days ago about the new features of XSLT 2, describing
something about grouping.
Also this morning, I found Jennies mail with her suggestion for XSLT 2.
So I took my good young Saxon horse from stable, and started working
with that. Thanks to Jeni's mail I could then solve the problem in less
than 15 minutes.
Please find the stylesheet below.
I would dare to say that XSLT 2 is a blessing for mankind, as it makes
many thinks considerably easier.
I will definitely use XSLT 2 for my real project, where I need to
convert a flat structure with 92 items into a deep structure with
something like 8 levels of deepness. Guess doing that with XSLT1 is
something like a nightmare.
Many thanks - this is a great mail list.
The code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="root">
<xsl:element name="result">
<xsl:for-each-group select="line" group-by="item[(_at_)itemcount = 1]">
<xsl:element name="A">
<xsl:attribute name="Value"><xsl:value-of
select="current-grouping-key()"/></xsl:attribute>
<xsl:for-each-group select="current-group()"
group-by="item[(_at_)itemcount = 2]">
<xsl:element name="B">
<xsl:attribute name="Value"><xsl:value-of
select="current-grouping-key()"/></xsl:attribute>
<xsl:for-each-group select="current-group()"
group-by="item[(_at_)itemcount = 3]">
<xsl:element name="C">
<xsl:attribute name="Value"><xsl:value-of
select="current-grouping-key()"/></xsl:attribute>
<xsl:for-each-group select="current-group()"
group-by="item[(_at_)itemcount = 4]">
<xsl:element name="D">
<xsl:attribute name="Value"><xsl:value-of
select="current-grouping-key()"/></xsl:attribute>
<xsl:for-each select="item[(_at_)itemcount=5]">
<xsl:element name="E">
<xsl:attribute name="Value"><xsl:value-of
select="."/></xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:template>
</xsl:stylesheet>