[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: outputting unknown amount of child 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|