This is a short and simple conversion (without explicit conditions at all) :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="book[price=29.99]/title/@lang">
<xsl:attribute name="lang">ChangedLang</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
when applied to the provided XML (wrapped in a well-formed XML document):
<t>
<book>
<title lang="fr">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</t>
creates the desired, correct result :
<t>
<book>
<title lang="ChangedLang">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</t>
The explanation . Overriding the rule for the desired attribute.
source
share