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

Re: outputting unknown amount of child elements

Subject: Re: outputting unknown amount of child elements
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 5 Feb 2004 12:35:06 +0000
the amount of elements
Hi David,

> How can I process this so all child elements (regardless of the
> depth) are outputted in a way that mirrors the structure structure
> of the original document.

Write a template that matches the given element, and within that
template, apply templates to the children of the element. For example,
something like:

<xsl:template match="item">
  <!-- Output the word 'Heading' if the item has child items -->
  <xsl:if test="item">Heading </xsl:if>
  <!-- Apply templates to the children of this item, including the
       text -->
  <xsl:apply-templates />
</xsl:template>

You don't have to know how many levels there might be: the template
keeps being applied recursively down the tree.

By the way, if you have control over the design of the XML that you're
using, you might consider changing it so that the <item> elements that
contain other <item> elements wrap the heading in a <heading> (or
similar) element. Having mixed content in such structures is usually
bad news when it comes to XSLT processing.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.