I have a XML:
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<tag1 id="abc" name="first tag">
<tag2 id="efg" name="embedded tag1">
</tag2>
</tag1>
<tag1 id="hij" name="first tag">
<tag2 id="hij" name="embedded tag1">
</tag2>
</tag1>
<LOTS OF TAG1/TAG2S>...</>
</ROOT>
I would like to find out the nodes tag2 which have the same id value as the parent node tag1's id value, replace the value of tag2 id to original id with suffix "D".
In above example: tag2 has id "hij" which is the same as its parent node tag1, hence it should be replaced as:
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<tag1 id="abc" name="first tag">
<tag2 id="efg" name="embedded tag1">
</tag2>
</tag1>
<tag1 id="hij" name="first tag">
<tag2 id="hijD" name="embedded tag1">
</tag2>
</tag1>
<LOTS OF TAG1/TAG2S>...</>
</ROOT>
I wrote an xslt:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//tag2/@id[.=../tag1/@id]">
<xsl:with-param name="id" select="@id" />
<xsl:with-param name="extra" select="'D'" />
<xsl:attribute name="id">
<xsl:value-of select="concat($id,$extra)"/>
</xsl:attribute>
</xsl:template>
Doesn't quite work as expected. Any lights would be appreciated!