Re: my first question !

Subject: Re: my first question !
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 21 Nov 2000 15:10:15 +0000
Shlomi,

> the thing is that I need to implement a recursive method that goes
> down in the tree !

XSLT generally works by looking at a node, finding templates that
match that particular node, and applying them to give some output.
There are default templates that match on an element (e.g. your
'list' and 'object' elements) and apply templates to its children.
This gives you the effect of walking down the document tree from
element to element.

In other words, XSLT is built on a recursive method already. All you
have to do is encode the rules that should govern what the processor
does when it comes across a node of a particular type.

For example, in your XML you have objects listed inside lists, which
are listed inside lists themselves and so on. Lets say you want to
create HTML unordered lists from this information.  Each 'list'
element should give an unordered list within a list item:

<xsl:template match="list">
  <li>
     <ul>
       <!-- apply templates to children of the list -->
       <xsl:apply-templates />
     </ul>
  </li>
</xsl:template>

The exception to this is the top-most list, which should give a list
that isn't itself within a list item:

<xsl:template match="/list">
  <ul>
    <!-- apply templates to children of the list -->
    <xsl:apply-templates />
  </ul>
</xsl:template>

Each of the objects within the list is a list item:

<xsl:template match="objects">
  <li><xsl:apply-templates /></li>
</xsl:template>

The xsl:apply-templates instructions are the ones that give you the
recursion down the document tree: they tell the processor to apply
any templates that it can find to the children of the current node.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread