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

Re: how to match attributes in templates?

Subject: Re: how to match attributes in templates?
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Wed, 22 Jan 2003 23:09:16 +0000
xslt match attribute
Hi Alice,

Alice Fan wrote:

this is what i'm doing to copy all nodes except for a specific element name. how do i specify a specific attribute inthe if statement?

Well, you can find an example of how to copy all nodes in the XSLT spec (in the identity transform described at http://www.w3.org/TR/xslt#copying) and you can build on this to match and trap a specific attribute (or element)


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

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

 <!-- ...except this one -->
 <xsl:template match="@id" />

</xsl:stylesheet>

This is somewhat similar to what you were trying to do, but matching templates by pattern is more fun (and more in the spirit of XSLT) than coding xsl:if statements.

But if you do want to use explicit logic rather than pattern matching, you can use:

<xsl:if test="not(self::someelement)">...</xsl:if>

if you know the element name at build time, or use:

<xsl:if test="not(localname() = $targetNodeName)">...</xsl:if>

if the element name will be set at run time.

Francis.





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.