Hi.
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
florian
Sent: Thursday, June 05, 2003 4:23 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Cc: davidc(_at_)nag(_dot_)co(_dot_)uk
Subject: Re: [xsl] 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[(_at_)name=current()/@dataListName]">
<xsl:with-param name="cnn"
select="preceding-sibling::list[(_at_)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