Description
Input XSL
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common">
<xsl:output method="xml" indent="yes" />
<!-- ********************************************* -->
<xsl:template match="/body/div//a" mode="test-mode">
<xsl:copy>
<xsl:attribute name="new_attr">1</xsl:attribute>
<xsl:apply-templates select="@*|node()" mode="test-mode" />
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*" mode="test-mode">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="test-mode" />
</xsl:copy>
</xsl:template>
<!-- ********************************************* -->
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="." mode="test-mode" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Input XML
<body>
<div>
<div>
<a href="abc.pdf" >Testing</a>
</div>
</div>
</body>
Expected Output:
<?xml version="1.0"?>
<body>
<div>
<div>
<a new_attr="1" href="abc.pdf">Testing</a>
</div>
</div>
</body>
Actual Output:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<div>
<div>
<a href="abc.pdf">Testing</a>
</div>
</div>
</body>
I receive the expected results when I run this transformation through xsltproc on Linux.