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

RE: XSLT - update attribute with new value

Subject: RE: XSLT - update attribute with new value
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 9 Nov 2004 14:16:40 -0000
xml update attribute
> Hi David and Michael,

It's best not to address questions to specific people. Sometimes in an
initial response I try to point people in the right direction, but that
doesn't necessarily mean I'm prepared to hold their hands all the way down
the road - whereas someone else might well be happy to do so.
> 
> Now I have one final question. I want to add an attribute/value to the
> xml tree only if that attribute does not exist anywhere in 
> the document
> source tree.
> 
> Is there a way to do that in XSLT?

You can test whether the attribute is absent from the tree with 

<xsl:if test="not(//@x)">

But remember that your stylesheet code must be structured to mirror the
result tree structure, not the source tree structure. So you have to put
this code in the template rule for the element that is to carry the new
attribute. If this template rule is evaluated repeatedly, it will be more
efficient to put the condition

<xsl:variable name="x-is-absent" select="not(//@x)"/>

in a global variable.

Michael Kay
http://www.saxonica.com/

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.