Re: [xsl] manipulate xml with xsl/javascript, save with asp/vbscript

Subject: Re: [xsl] 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