Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 17th, 2008, 03:09 AM
Authorized User
 
Join Date: Jun 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default change an attribute value

Im copying the entire document but I need to replace the attribute value of name below to "orange"? Please help.

From
.
.
<inc:targetName type="fruit" name="apple" />
.
.


To
.
.
<inc:targetName type="fruit" name="orange" />
.
.




 
Old October 17th, 2008, 03:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Use the "modified identity template" coding pattern.

An identity template for the things to be copied:

<xsl:template match="*">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

supplemented by a rule that changes the things you want to change:

<xsl:template match="inc:targetType[@name='apple']">
  <xsl:copy>
    <xsl:copy-of select="@type"/>
    <xsl:attribute name="name">orange</xsl:attribute>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 17th, 2008, 04:52 AM
Authorized User
 
Join Date: Jun 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're an angel, Michael!

Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Sort-by attribute based on parent tclancy XSLT 2 March 24th, 2006 05:00 PM
XSLT change class attribute by ID? matallen XSLT 8 March 1st, 2006 05:00 PM
Problem using XSLT to change XML attribute cbeech1980 XSLT 1 October 18th, 2005 06:26 AM
Change 1 attribute safin XSLT 1 October 3rd, 2005 12:19 PM
Change style attribute of a WebUserControl YiannisF ASP.NET 1.0 and 1.1 Basics 1 July 10th, 2004 02:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.