Subject: Re: [xsl] outputting unknown amount of child elements From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 5 Feb 2004 12:35:06 +0000 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] outputting unknown amount of , David Elsmore | Thread | Re: [xsl] outputting unknown amount, Emmanuil Batsis (Man |
[xsl] outputting unknown amount of , David Elsmore | Date | Re: [xsl] outputting unknown amount, Emmanuil Batsis (Man |
Month |