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

RE: Changing an attribute wherever it may occur

Subject: RE: Changing an attribute wherever it may occur
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 27 Sep 2001 16:17:12 -0400
changing action attribute
Matt--

Do just what he said, only qualify the match by whatever your criterial actually are.

So, Chris had (modified slightly for conciseness):

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

<xsl:template match="@Action">
  <xsl:attribute name="Action">M</xsl:attribute>
</xsl:template>

But you want

to do it for the <A> elements that met a
certain criteria, such as @Id='X', as opposed to the whole document?

So change that second template to


<xsl:template match="A[@Id='X']//@Action">
  <xsl:attribute name="Action">M</xsl:attribute>
</xsl:template>

or just

<xsl:template match="A[@Id='X']//@Action">
  <xsl:copy>M</xsl:copy>
</xsl:template>

Any Action attribute nodes anywhere inside an A whose Id='X', will be changed to have value "M".

To explicate further, '//' is short for /descendant-or-self::node()/, so you are saying you want to match on any Action attribute attached to any A with Id='X', or attached to any descendant of such an A. It will fail to match Action attributes that are not attached to, or descendants of, such an A.

This is a good example of how compact and elegant XSLT can get when you understand both the power of template matching and applying, and how to construct XPath expressions that match (or select) just what you want.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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-2011 All Rights Reserved.