[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Stupid beginner question: recursing a list of (kind of

Subject: Stupid beginner question: recursing a list of (kind of) nested elements
From: Graham Hannington <Ghannington@xxxxxxx>
Date: Wed, 8 Jan 2003 19:25:03 -0000
fox outline
I have a document containing elements like this:


<topic file="1.htm">One</topic>

<topic file="2.htm">Two</topic>

<subtopics>

  <topic file="2a.htm">Two Ay</topic>

  <topic file="2b.htm">Two Bee</topic>

  <subtopics>

    <topic file="2bi.htm">Two Bee Eye</topic>

    <topic file="2bi.htm">Two Bee Eye Eye</topic>

  </subtopics>

</subtopics>

<topic file="3.htm">Three</topic>


that I want to into properly nested elements, similar to this:


<fox:outline>

  <fox:label>One</fox:label>

</fox:outline>

<fox:outline>

  <fox:label>Two</fox:label>

  <fox:outline>

    <fox:label>Two Ay</fox:label>

    <fox:label>Two Bee</fox:label>

    <fox:outline>

      <fox:label>Two Bee Eye</fox:label>

      <fox:label>Two Bee Eye Eye</fox:label>

    </fox:outline>

  </fox:outline>

</fox:outline>

<fox:outline>

  <fox:label>Three</fox:label>

</fox:outline>


I've achieved this, but only by resorting to a truly stupid set of nested
<xsl:for-each> tags (which will only work up to three <subtopics> deep).

I'd like to use a more elegant recursive template, but my attempts so far
have resulted in properly nested elements (as desired), interspersed with
unwanted duplicates.  My attempts so far are all variations on this theme:

	<xsl:template match="topic" mode="outline">

		<fox:outline>
			<fox:label>
				<xsl:value-of select="." />
			</fox:label>

			<!-- If the next tag is a subtopics, then apply
templates to its children -->
			<xsl:apply-templates
select="following-sibling::*[1][self::subtopics]/child::*" mode="outline" />

		</fox:outline>

	</xsl:outline>

The problem is, I don't know how to exclude <topic> tags from processing by
the template when they've already been processed (at least, I think that's
the problem).

Graham Hannington

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.