Hi I have to replace more than one attributes of a given tag using XSLT while copying the entire file with identity template. With my given XSLT I’m able to replace one attribute (value of class) but not the other one.
Input file:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
<meta http-equiv="Content-type" content="text/html; charset=us-ascii" />
<title></title>
</head>
<body>
<!--OTHER STUFF-->
<div class="LR" id="12">
</div>
<!--OTHER STUFF-->
</body>
</html>
Output file:
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<title></title>
</head>
<body>
<!--OTHER STUFF-->
<div class="WZ" id="56">
</div>
<!--OTHER STUFF-->
</body>
</html>
My XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:div[@id='12']/@class">
<xsl:attribute name="class">WZ</xsl:attribute>
<xsl:attribute name="id">56</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Thanking you!
Try matching
@*:This gives the desired result: