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

Re: select only some elements and attributes

Subject: Re: select only some elements and attributes
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Feb 2001 09:18:18 +0000
xsl copying leaving out
Hi Meili,

> Hi, What's the best way to only select some elements and attributes
> using xslt?

Evan's shown you one way (a push method), which involves selecting all
the elements and attributes, copying most of them and not copying the
ones that you don't want. That's the easiest way to do it if you want
to copy the majority of the nodes, and just want to leave out a few
(or if the nodes that you want to leave out are easily identified).

If you want to only keep a smaller proportion of the nodes, then it's
best to select the ones that you *do* want to keep and just copy those
(a pull method). In your case, this alternative gives something like:

<xsl:template match="product">
   <xsl:copy>
      <xsl:copy-of select="@sku" />
      <xsl:copy-of select="title" />
      <xsl:copy-of select="price" />
      <xsl:copy-of select="weight" />
      <xsl:apply-templates select="vendor" />
   </xsl:copy>
</xsl:template>

<xsl:template match="vendor">
   <xsl:copy>
      <xsl:copy-of select="company" />
      <xsl:copy-of select="phone" />
   </xsl:copy>
</xsl:template>

If the ordering in the source and the result is the same, then you can
combine the xsl:copy-of instructions together to make it shorter:

<xsl:template match="product">
   <xsl:copy>
      <xsl:copy-of select="@sku | title | price | weight" />
      <xsl:apply-templates select="vendor" />
   </xsl:copy>
</xsl:template>

<xsl:template match="vendor">
   <xsl:copy>
      <xsl:copy-of select="company | phone" />
   </xsl:copy>
</xsl:template>

I hope that helps,

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.