RE: [xsl] simple tree problem ...

Subject: RE: [xsl] simple tree problem ...
From: "Christopher R. Maden" <crism@xxxxxxxxx>
Date: Thu, 25 Oct 2001 04:23:07 -0700
At 02:57 25-10-2001, Michael Kay wrote:
> First there was a tree ...
> <snip>
> <position>         1
>    <position>      2
>      <position/>   3
>    </position>
>    <position/>     4
> </position>
> <position/>        5
> </snip>

One way of doing a breadth-first tree walk is:

<xsl:template match="position">
  <xsl:apply-templates select="child::position" mode="visit"/>
  <xsl:apply-templates select="child::position"/>
</xsl:template>

<xsl:template match="position" mode="visit">
  <xsl:value-of select="."/>
</xsl:template>

Except that that latter template will get the contents of the position and all its descendants. That would give


contents-of-1-2-3-and-4
contents-of-5
contents-of-2-and-3
contents-of-4
contents-of-3

<xsl:template match="position" mode="visit">
  <xsl:apply-templates select="text()"/>
</xsl:template>

might be better.

(Of course, Mike's example was only illustrative, but pedantry is the order of the day.)

-Chris
--
Christopher R. Maden, Principal Consultant, HMM Consulting Int'l, Inc.
DTDs/schemas - conversion - ebooks - publishing - Web - B2B - training
<URL: http://www.hmmci.com/ > <URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA


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



Current Thread