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

Re: Re: file manipulation with recursion

Subject: Re: Re: file manipulation with recursion
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 23 Jul 2002 15:29:42 +0100
file manipulation copy
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


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.