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

Re: template match attributes

Subject: Re: template match attributes
From: "Bob DuCharme" <bob@xxxxxxxxx>
Date: Tue, 29 May 2001 14:55:18 -0400
template match attribute
> Is it possible to match attributes in a template match?
>
> <xsl:template match="//path/mypath/@type">

Sure. Just remember that when you match an attribute node of your source
tree, if you've copied its parent node to the result tree, you can't hang
just anything off the result tree version of the parent node. For example,
to transform this source document,

<path>
    <mypath type="blood" flavor="mint">
    The mypath content
    </mypath>
  </path>

the following stylesheet will replace the type attribute with a color="blue"
attribute value pair, but trying to add the empty test element to the same
place in the result tree wouldn't work:

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:template match="//path/mypath/@type">
    <xsl:attribute name="color">blue</xsl:attribute>
    <!-- this wouldn't work: <test/> -->
  </xsl:template>

  <!-- Copy all the other nodes -->
  <xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
  </xsl:template>

  </xsl:stylesheet>

(By the way, you probably don't need the "//" at then beginning of your
XPath expression, especially if path really is the root element.)

Bob DuCharme            www.snee.com/bob             <bob@
snee.com>      see http://www.snee.com/bob/xsltquickly for
info on upcoming "XSLT Quickly" from Manning Publications.



 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.