[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XSLT - update attribute with new value
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>
|
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
|