Subject: Re: [xsl] 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 |
Cheers, Wendell
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 ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Stupid beginner question: rec, Graham Hannington | Thread | [xsl] XPath Problem., Sandeep_Karandikar |
[xsl] Stupid beginner question: rec, Graham Hannington | Date | [xsl] XPath Problem., Sandeep_Karandikar |
Month |