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

RE: How to transform flat structure into hierarchical one?

Subject: RE: How to transform flat structure into hierarchical one?
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Wed, 07 Jun 2000 17:27:22 +0100
how to sort hierarchical records
Aleksandrs,

Paulo Gaspar wrote:
>And the typical algorithm to group the nodes has you wish involves a few
>logical steps:
> A - Sort the nodes by house number;
> B - Separate the records in groups with the same house_id.

When I read this, I realised that I forgot to include in my reply to you
anything about sorting the rooms and houses within your records.  It is
very easy to add sorting to the solution that I sent earlier: you use an
xsl:sort element within each xsl:for-each, with the select attribute
indicating the thing that you want to sort by.  So in your case:

<xsl:template match="record_set">
  <house_list>
    <!-- cycle through the first records in each group -->
    <!-- in order based on house_id -->
    <xsl:for-each select="record[generate-id() = generate-id(key('records',
house_id)[1])]">
      <xsl:sort select="house_id" />
      <house>
        <id><xsl:value-of select="house_id" /></id>
        <rooms>
          <!-- cycle through each of the records in the group -->
          <!-- in order based on room_id -->
          <xsl:for-each select="key('records', house_id)">
            <xsl:sort select="room_id" />
            <room>
              <id><xsl:value-of select="room_id" /></id>
            </room>
          </xsl:for-each>
        </rooms>
      </house>
    </xsl:for-each>
  </house_list>
</xsl:template>

The same thing can be done with xsl:apply-templates (by including an
xsl:sort within the xsl:apply-templates element), if you were using that
instead.

Sorry for the ommission.

Cheers,

Jeni

Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email
jeni.tennison@xxxxxxxxxxxxxxxx



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.