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

RE: Re: Re: SOLVED - flat structure to deep str

Subject: RE: Re: Re: SOLVED - flat structure to deep structure in a smart way
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 25 Sep 2004 09:49:01 +0100
what is a flat structure
This solution, with 5 levels of grouping, can actually be generalized to an
arbitrary depth by using recursion. It looks something like this:

<xsl:template name="group">
  <xsl:param name="population" as="element(line)*" required="yes"/>
  <xsl:param name="depth" as="xs:integer" select="1"/>
  <xsl:element name="substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ', $depth, 1)">
    <xsl:attribute name="Value"><xsl:value-of
                      select="current-grouping-key()"/>
    </xsl:attribute>
    <xsl:for-each-group select="$population"
group-by="item[@itemcount=$depth]">
      <xsl:call-template name="group">
        <xsl:with-param name="population" select="current-group()"/>
        <xsl:with-param name="depth" select="$depth+1"/>
      </
    </
  </
</

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: jozef.aerts@xxxxxxxxxxxxxx [mailto:jozef.aerts@xxxxxxxxxxxxxx] 
> Sent: 25 September 2004 09:34
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Re: Re: SOLVED -  flat structure to deep 
> structure in a smart way
> 
> 
> 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.