RE: How to transform flat structure into hierarchical one?

Subject: RE: How to transform flat structure into hierarchical one?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 06 Jun 2000 17:46:59 +0100

At 08:47 PM 6/6/00 +0200, you wrote:

>Sorry, but IMO it is absolutely another problem than what is discussed in
>the FAQ list you have suggested. I have no idea how many "rooms" in each

But without knowing that, you want them to be gathered together in a
"wrapper" element by house, right?

>    <house>
>        <id>h1</id>
>        <rooms>
>            <room>
>                <id>r1</id>
>            </room>
>            <room>
>                <id>r2</id>
>            </room>
>        </rooms>
>    </house>
>    <house>
>        <id>h2</id>
>        <rooms>
>            <room>
>                <id>r3</id>
>            </room>
>        </rooms>
>    </house>

> And I don't want to search all records containing "houses" with
>the same id, because it degrades performance significantly

It's true XSLT is not the fastest way to perform this kind of operation --
but if that's how your output will be organized, how would you get around

> (BTW, I don't
>understand how SQL can return me anything else than the flat structure I
>have described).

That might be the key statement there. I don't know SQL syntax myself, but
I know that this is just the kind of thing SQL is designed to do. Maybe a
helpful reader will risk the wrath of and go off topic to
suggest what the SQL syntax would look like.

> My question is what way should I create XSLT to make
>transformation as fast as possible using the fact that SQL result set is
>already grouped and sorted according to my needs?

Well, if it were already grouped and sorted according to your needs, the
transformation would be very fast (or unnecessary). But in the sample input
you provided, it wasn't. I see two records here with house_id containing
'h1' -- not grouped.

>    <record>
>        <house_id>h1</house_id>
>        <room_id>r1</room_id>
>    </record>
>    <record>
>        <house_id>h1</house_id>
>        <room_id>r2</room_id>
>    </record>
>    <record>
>        <house_id>h2</house_id>
>        <room_id>r3</room_id>
>    </record>

Now maybe you're getting all your h1 houses first, then h2 etc. (your
example doesn't show). In that case, if you wrapped them together on
output, you'd have your grouping and XSLT would have a much easier time.

Mike is correct. You should either do some research on SQL, or think a bit
harder about the transformation you're trying to get XSLT to do.

Good luck,

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

 XSL-List info and archive:

Current Thread