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)
|
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 |
- RE: Embedding XSL in JavaScript, (continued)
- John Proctor - Wed, 5 Mar 2003 12:02:11 -0500 (EST)
- XSLList - Wed, 5 Mar 2003 14:09:29 -0500 (EST)
- Mac Martine - Wed, 12 Mar 2003 13:18:18 -0500 (EST)
- Mac Martine - Wed, 12 Mar 2003 14:13:48 -0500 (EST)
- Mike Brown - Wed, 12 Mar 2003 14:35:19 -0500 (EST) <=
- XSLList - Wed, 12 Mar 2003 15:20:20 -0500 (EST)
- Americo Albuquerque - Wed, 12 Mar 2003 14:51:05 -0500 (EST)
- john liao - Sat, 15 Mar 2003 17:58:32 -0500 (EST)
- Joe Fawcett - Sun, 16 Mar 2003 03:20:33 -0500 (EST)
|
|