[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT - update attribute with new value
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 ________________________________________________________________________
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|