Hi,
I must add an attribute to an already existing node (with children) according to one of the other attributes' value:
<node attr1="1"><child/></node>
if test @attr1=1 add attr2="y"
else add attr2="n"
result:
<node attr1="1" attr2="y"><child/></node>
the problem is that I can't add attributes due to node's child:
Code:
<xsl:choose>
<xsl:when test="@attr1='1'">
<xsl:attribute name="attr2">y</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="atte2">n</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
reports an error:
xsl:attribute: Cannot add attributes to an element if children have been already added to the element.
and copying makes a mess of things:
Code:
<xsl:choose>
<xsl:when test="@attr1='1'"><xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="attr2">y</xsl:attribute>
<xsl:copy-of select="*"/>
</xsl:copy></xsl:when>
<xsl:otherwise><XSL-copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="attr2">n</xsl:attribute>
<xsl:copy-of select="*"/>
</xsl:copy></xsl:otherwise>
</xsl:choose>
this generates:
<node attr1="1"><child/><node attr1="1" attr2="y"></node></node>
What do I do???
thank you,
Eran