I need to add attribute and new node to existing node
example :
<doc>
<a></a>
<a></a>
<a></a>
<d></d>
<a></a>
<f></f>
</doc>
what i need is add now attrinute to <a> node and add new node inside a node.
so the output would be,
<doc>
<a id='myId'> <new_node attr="myattr"/> </a>
<a id='myId'> <new_node attr="myattr"/> </a>
<a id='myId'> <new_node attr="myattr"/> </a>
<d></d>
<a id='myId'> <new_node attr="myattr"/> </a>
<f></f>
</doc>
I wrote following code to do this task,
<xsl:template match="a">
<xsl:apply-templates select="@*|node()"/>
<xsl:copy>
<xsl:attribute name="id">
<xsl:value-of select="'myId'"/>
</xsl:attribute>
</xsl:copy>
<new_node>
<xsl:attribute name="attr">
<xsl:value-of select="'myattr'"/>
</xsl:attribute>
</new_node>
</xsl:template>
this code adds the new attribute and new node as expected but the problem is it only adds to the first node and it do not compile after this and five following message in oxygen editor. ' An attribute node (id) cannot be created after a child of the containing element.
How can I solve this issue ?