[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: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 4 Nov 2004 14:09:32 GMT
rewrite attribute xsl
  The XSLT stylesheet nees to search for the var and replace its value
  with the new value.  It must also rewrite the rest of the file. The
  program performs other functions that are needed by the stylesheet and
  best performed by the program so the XSLT stylesheet's function is just
  to accept the var and value from the program and update the value in the
  XML file.

so your stylesheet is basically an identity transform, there is one in
the XSL REC and dozens in the archive of this list:


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

but you need a couple of parameters (declared first)
<xsl:param name="attr"/>
<xsl:aram anme="value"/>

and then you want a template that fixes up that attribute

<xsl:template match="@*[name()=$attr]">
which you could do in xslt 2 draft but annoyingly you can't have
variables in match patterns in xslt 1 so instead match on all attributes
and test inside the template

<xsl:template match="@*" priority="10">
<xsl:attribute name="{name()}">
 <xsl:choose>
   <xsl:when test="name()=$attr"><xsl:value-of select="$value"/></xsl:when>
   <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
  </xsl:choose>
</xsl:attribute>
</xsl:template>


and that should be all you need.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.