RE: [xsl] Selecting and printing certain nodes

Subject: RE: [xsl] Selecting and printing certain nodes
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Fri, 20 Feb 2004 18:03:37 +0100
> -----Original Message-----
> From: Glenn MacGregor
<snip />
> This all work great. Now my question is can you think of a way to handle
> nested foreach statments?
> <foreach param="devices">
> <tr><td colspan="2"><variable/></td></tr>
> <foreach param="parameters">
> <tr><td><variable/></td></tr>
> </foreach>
> </foreach>

Hmm. If you would have a template to match foreach-elements, and you
apply-templates without selecting any node in particular, then the processor
should do all the rest for you, pushing the descendant::foreach --no matter
what depth - through its matching template and treat it the same way as the
higher level foreach...

So, by adding this
<xsl:template match="foreach">
  <xsl:apply-templates select="do" />

the do-template in my example, with a slightly modified variable (otherwise
it suffers the same defects as pointed out by David and Wendell --text will
not be selected) will ensure that the descending foreach's have a matching
template that is of higher priority than the node() template.

So, make the variable
<xsl:variable name="vdo" select="node()" />

If the do element (or in your altered design: the descendant nodes of the
foreach) contain(s) nested foreach elements, this template will treat
*their* descendants (the do, or, if you will, 'body' of the foreach) as they
are encountered, and will use the other already defined templates to provide
you with the correct result.

> Do I need to pass a variable which is an array or something

So the answer to this one would be: no.



 XSL-List info and archive:

Current Thread