[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT - update attribute with new value

Subject: XSLT - update attribute with new value
From: Ann Marie Rubin <Annmarie.Rubin@xxxxxxx>
Date: Wed, 10 Nov 2004 17:32:49 -0500
marie rubin
Many thanks to everyone who offered help with my stylesheet. Everyone's
suggestions worked when using a hardcoded value for the attribute name. 
But I need to use parameters.

this is what I've tried so far.  Is there another way?

thanks,


Ann Marie

<xsl:param name="attr">ROSE</xsl:param>
<xsl:param name="value">RED</xsl:param>
<xsl:param name="node">orion-web-app</xsl:param>

 <xsl:template match="orion-web-app"> 
 <!-- adds attr to orion-web-app node correctly but won't
    take vars for attr or match="$node" -->

    <xsl:copy>
         <xsl:if test="not(//@ROSE)">
               <xsl:attribute name="ROSE"><xsl:value-of
select="$value"/></xsl:attribute>
               <xsl:apply-templates select="@*|node()"/>
         </xsl:if>  
    </xsl:copy> 
 
     </xsl:template>
 
If i include the attr test in this template:

 <xsl:template match="@*" priority="10">
 <!--   adds attr to each node in the tree
         it should only be added to the specified node
         and vars are not allowed where ROSE is used -->

         <xsl:if test="not(//@ROSE)">
           <xsl:attribute name="ROSE"><xsl:value-of
select="$value"/></xsl:attribute>
         </xsl:if>-->  


to get around the restriction on where attribute names can be used, I
tried this:

<xsl:template match="@*" priority="10">
       <!--replaces every attr in the result tree w/ RED
        recoverable error: Cannot write an attribute node when no
        element start tag is open-->
     
        <xsl:choose>
        <xsl:when test="not(//@*=$attr)"><xsl:value-of
select="$value"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
        </xsl:choose>

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.