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

Re: Re: SOLVED - flat structure to deep structu

Subject: Re: Re: SOLVED - flat structure to deep structure in a smart way
From: <jozef.aerts@xxxxxxxxxxxxxx>
Date: Sat, 25 Sep 2004 10:34:01 +0200
xsl for each group flat
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[@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[@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[@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[@itemcount = 4]">
                    <xsl:element name="D">
                      <xsl:attribute name="Value"><xsl:value-of
select="current-grouping-key()"/></xsl:attribute>
                      <xsl:for-each select="item[@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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.