When this XML document is open on browser:
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test XSLT javascript injektion</title>
</head>
<body>
<h2>Test XSLT javascript injektion</h2>
<ul>
<li><a href="http://www.google.com">Google</a></li>
<li><a href="http://www.stackoverflow.com">Stack Overflow</a></li>
</ul>
</body>
</html>
And this stylesheet as "test.xsl":
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" omit-xml-declaration="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:template match="processing-instruction()" priority="1"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:a/node()[1]">
<xsl:attribute name="onclick">
<xsl:value-of select='concat("alert('",..,"')")'/>
</xsl:attribute>
<xsl:call-template name="identity"/>
</xsl:template>
</xsl:stylesheet>
Output:
<!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>
<title>Test XSLT javascript injektion</title>
</head>
<body>
<h2>Test XSLT javascript injektion</h2>
<ul>
<li>
<a href="http://www.google.com" onclick="alert('Google')">Google</a>
</li>
<li>
<a href="http://www.stackoverflow.com" onclick="alert('Stack Overflow')">Stack Overflow</a>
</li>
</ul>
</body>
</html>
And alerts works on click.