[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: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Wed, 10 Nov 2004 15:47:09 -0800
xslt update variable
Hi Ann Marie,

Ann Marie Rubin wrote:

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.


Just as is the case with adding dynamic data inline to any attribute you
simply use ="{dynamic logic or assignment of variable value}".

Without looking back at the previous threads to determine the best
approach to determine what the value of attribute name should be you
could do something like this:

<xsl:variable name="attName">
   <xsl:choose>
      <xsl:when test="test to determine value of this boolean">
         ROSE
      </xsl:when>
      <xsl:otherwise>
         NOT A ROSE
      </xsl:otherwise>
   </xsl:choose>
</xsl:variable>

...
<xsl:attribute name="{$attName}">
   <xsl:value-of select="$value"/>
</xsl:attribute>
...

HTH's!

<M:D/>

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.