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

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">
    <!-- 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',
      <xsl:sort select="house_id" />
        <id><xsl:value-of select="house_id" /></id>
          <!-- 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" />
              <id><xsl:value-of select="room_id" /></id>

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

Sorry for the ommission.



Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email

 XSL-List info and archive:

Current Thread