I want to create a XSLT Transformation which loops through any XML Structure and replaces a specific value. For example:
Input XML:
<?xml version="1.0" encoding="UTF-8"?>
<Node1>
<Node2>
<Node3>
<Tag1>1</Tag1>
<Tag2>2</Tag2>
<Tag3>3</Tag3>
</Node3>
</Node2>
</Node1>
Let´s say I want to replace any Value "2" with "1"
Expected Output XML:
<?xml version="1.0" encoding="UTF-8"?>
<Node1>
<Node2>
<Node3>
<Tag1>1</Tag1>
<Tag2>1</Tag2>
<Tag3>3</Tag3>
</Node3>
</Node2>
</Node1>
I already tried to loop with the xsl:for-each and xsl:if Statements, but it doesn´t work:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:copy-of select=".">
<xsl:for-each select=".">
<xsl:if test="xsl:value-of select = '2'">
xsl:value-of select = '1'
</xsl:if>
</xsl:for-each>
</xsl:copy-of>
</xsl:template>
</xsl:stylesheet>
I assume the xsl:value-of part is not correct, but I don´t really know how to access the value of the Tag in the condition.