This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Re: file manipulation with recursion
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Holmberg Rick-ra0119 <Rick dot Holmberg at motorola dot com>
- Cc: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 23 Jul 2002 15:29:42 +0100
- Subject: Re: [xsl] Re: file manipulation with recursion
- Organization: Jeni Tennison Consulting Ltd
- References: <7146D19B7FC9D5119F6400D0B7B99308022246FD@az33exm22.corp.mot.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Rick,
> Thanks for all your help. I have a little twist to this file
> however. Under each category node there could be zero, one or many
> product nodes. I want to just display the id and name of the product
> node as well, and they can appear under any category node. The
> initial file format would be of the following...
Then apply templates to the product elements as well as the category
elements, and have a template for the product elements that creates a
product element with the name and id inside:
<xsl:template match="category">
<xsl:copy>
<xsl:copy-of select="id" />
<xsl:copy-of select="name" />
<xsl:apply-templates select="category | product" />
</xsl:copy>
</xsl:template>
<xsl:template match="product">
<xsl:copy>
<xsl:copy-of select="id" />
<xsl:copy-of select="name" />
</xsl:copy>
</xsl:template>
(You could probably actually combine these templates into:
<xsl:template match="category | product">
<xsl:copy>
<xsl:copy-of select="id" />
<xsl:copy-of select="name" />
<xsl:apply-templates select="category | product" />
</xsl:copy>
</xsl:template>
if you wanted.)
The general pattern in XSLT is that for each element in your XML you
have a template that shows how to map from that element to the element
that you want to create in the result.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list