Subject: RE: walking a tree
From: Americo Albuquerque <melinor@xxxxxxx>
Date: Thu, 5 Jun 2003 23:44:59 +0100
|
Hi.
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of florian
> Sent: Thursday, June 05, 2003 4:23 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Cc: davidc@xxxxxxxxx
> Subject: Re: walking a tree
>
>
(...)
>
>
> arg. and the output should look like::
>
> apple - 2
> orange - 5
>
> orange - 5
>
Try this:
<xsl:template match="root">
<!-- we start with the tree node -->
<xsl:apply-templates select="tree"/>
</xsl:template>
<xsl:template match="tree">
<!-- select the lis with name = @dataListName passing as parameters
the connections and the display -->
<xsl:apply-templates
select="preceding-sibling::list[@name=current()/@dataListName]">
<xsl:with-param name="cnn"
select="preceding-sibling::list[@name=current()/@connectionListName]"/>
<xsl:with-param name="dsp" select="display"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="list">
<xsl:param name="cnn"/>
<xsl:param name="dsp"/>
<xsl:apply-templates select="object">
<xsl:with-param name="cnn" select="$cnn"/>
<xsl:with-param name="dsp" select="$dsp"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="object">
<xsl:param name="cnn"/>
<xsl:param name="dsp"/>
<!-- display the current object acording to the ruls in the dsp
variable -->
<xsl:apply-templates select="$dsp/*">
<xsl:with-param name="data" select="."/>
</xsl:apply-templates>
<xsl:text> </xsl:text>
<!-- look for other objects connected to this -->
<xsl:apply-templates select="$cnn/connection[inId=current()/id]">
<xsl:with-param name="cnn" select="$cnn"/>
<xsl:with-param name="dsp" select="$dsp"/>
<xsl:with-param name="data" select=".."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="property">
<xsl:param name="data"/>
<xsl:apply-templates select="$data/*[name()=current()/@field]"/>
</xsl:template>
<xsl:template match="text">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="connection">
<xsl:param name="cnn"/>
<xsl:param name="dsp"/>
<xsl:param name="data"/>
<!-- display 4 spaces and select the outId object -->
<xsl:text>    </xsl:text>
<xsl:apply-templates select="$data/object[id=current()/outId]">
<xsl:with-param name="cnn" select="$cnn"/>
<xsl:with-param name="dsp" select="$dsp"/>
</xsl:apply-templates>
</xsl:template>
Using this xml:
<root>
<list name="foo">
<object>
<name>apple</name>
<size>2</size>
<id>1</id>
</object>
<object>
<name>orange</name>
<size>5</size>
<id>2</id>
</object>
.....
</list>
<list name="connections">
<connection>
<inId>1</inId>
<outId>2</outId>
</connection>
....
</list>
<tree dataListName="foo" connectionListName="connections" >
<display>
<property field="name" />
<text> - </text>
<property field="size" />
</display>
</tree>
</root>
Has this results:
apple - 2
orange - 5
orange - 5
Hope this helps you
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
- walking a tree
- florian - Thu, 5 Jun 2003 10:13:10 -0400 (EDT)
- David Carlisle - Thu, 5 Jun 2003 10:41:22 -0400 (EDT)
- florian - Thu, 5 Jun 2003 11:13:18 -0400 (EDT)
- florian - Thu, 5 Jun 2003 11:24:26 -0400 (EDT)
- Americo Albuquerque - Thu, 5 Jun 2003 18:47:05 -0400 (EDT) <=
|
|