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

Re: Stupid beginner question: recursing a list of (kin

Subject: Re: Stupid beginner question: recursing a list of (kind of) nested el ements
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 08 Jan 2003 14:28:26 -0500
fox outline
Graham,

It looks to me like all you need is a template to suppress the processing of the subtopics element when it is encountered on a normal traversal (since you have already accounted for it):

<xsl:template match="subtopics"/>

(Remember, the default rule is to apply templates to the element's children -- and that's what's happening here.)

I hope that helps!

Cheers,
Wendell

At 02:25 PM 1/8/2003, you wrote:
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


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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.