Subject: RE: Siblings to child - Hierarchy
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 22 Aug 2003 18:50:28 +0100
|
You can process this kind of hierarchy very easily.
Instead of using xsl:apply-templates in the usual way to process the
physical children of a node, use it to select and process the logical
children of the node:
<xsl:apply-templates select="//row[site_parent = current()/site_id]"/>
Then all you need is for the root template to select the logical top of
the hierarchy and do apply-templates on that.
For greater efficiency, use keys.
Michael Kay
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
> Todd Kleine
> Sent: 22 August 2003 16:06
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Siblings to child - Hierarchy
>
>
> Hello,
>
> 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>
>
> Has anyone had experience with this type of transform? Any
> help would be appreciated.
>
> Thanks in advance
>
> todd
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|