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

Re: manipulate xml with xsl/javascript, save with asp/

Subject: Re: manipulate xml with xsl/javascript, save with asp/vbscript
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 12 Mar 2003 12:38:37 -0700 (MST)
javascript save
Mac Martine wrote:
>  All I will be doing is adding an attribute to an element or two. The
> XSL does all the work of figuring out where to add the attribute, now I
> just need to figure out a slick way of adding that attribute

Use the identity transformation (a simple template found in the XSLT 1.0 spec
under "Copying") to make the default be to recursively copy all nodes from the
source tree to the result tree.

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

Add one template that matches the element that needs the new attribute. This
template should do the same recursive copy of its children, but only after
adding the new attribute:

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

It will match at a higher priority than the other template, so you don't
have to worry about conflicts.

> and saving the XML file with the added attribute

Saving the XSLT processor's output is a matter for the process that invoked
the XSLT processor.

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/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-2013 All Rights Reserved.