Subject: RE: Siblings to child - Hierarchy
From: "Todd Kleine" <tkleine@xxxxxxxxxxxxx>
Date: Fri, 22 Aug 2003 15:21:40 -0400
|
Thanks for everyone's help! Works like a charm.
-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Wendell Piez
Sent: Friday, August 22, 2003 1:53 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Siblings to child - Hierarchy
Todd,
I'd approach this by defining a key that would let me retrieve row elements
by their assigned parent:
<xsl:key name="row-by-parent" match="row" use="site-parent"/>
(Look up keys in a good reference to learn the details of how they work.)
Then I'd design a template matching rows:
<xsl:template match="row">
<site>
<!-- first, do whatever I'm going to do -->
<xsl:copy-of select="site_name | site_ID"/>
...
<!-- then, process its "children" using my key -->
<xsl:apply-templates mode="in-group" select="key('row-by-parent',
site_id)"/>
</site>
</xsl:template>
Doing this I'd get a recursive operation that would go all the way down the
tree.
In order to prevent repeat occurrences, initiate this process only for rows
with site-parent of 0:
<xsl:template name="rowset">
<xsl:apply-templates select="row[site_parent = 0]
</xsl:template>
I hope that's enough to get you going -- cool problem.
Cheers,
Wendell
At 11:06 AM 8/22/2003, you wrote:
>I am new to xsl and am having a tough time with a template to transform the
>results of an oracle "connect by" query into a hierarchical xml document.
>
>The xml results of a sample query is below:
>
><page>
> <rowset>
> <row>
> <site_id>1</site_id>
> <site_name>Test Parent1</site_name>
> <site_parent>0</site_parent>
> <level>1</level>
> <path>/0</path>
> </row>
> <row>
> <site_id>2</site_id>
> <site_name>Test Child1 of Test Parent1</site_name>
> <site_parent>1</site_parent>
> <level>2</level>
> <path>/0/1</path>
> </row>
> <row>
> <site_id>4</site_id>
> <site_name>Test Child1 of Test Child1</site_name>
> <site_parent>2</site_parent>
> <level>3</level>
> <path>/0/1/2</path>
> </row>
> <row>
> <site_id>3</site_id>
> <site_name>Test Parent2</site_name>
> <site_parent>0</site_parent>
> <level>1</level>
> <path>/0</path>
> </row>
> </rowset>
></page>
>
>where the site_parent value is the site_id of it's parent and a site_parent
>of 0 is a top-level node.
>
>I would like to produce a hierarchical xml doc based upon these results of
>the form
>
><site>
> <site_id>1</site_id>
> <site_name>Test Parent1</site_name>
> <site>
> <site_id>2</site_id>
> <site_name> Test Child1 of Test Parent1</site_name>
> <site>
> <site_id>4</site_id>
> <site_name>Test Child2 of Test Child1</site_name>
> </site>
> </site>
></site>
><site>
> <site_id>3</site>
> <site_name>Test Parent2</site_name>
></site>
======================================================================
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
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: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|