XSL transformation of SVG adds namespace attribute to new tag
Posted
by Steve
on Stack Overflow
See other posts from Stack Overflow
or by Steve
Published on 2010-03-29T14:35:45Z
Indexed on
2010/03/29
14:53 UTC
Read the original article
Hit count: 203
I have a SVG file that I want to extend by adding onclick handlers to edges and nodes. I also want to add a script tag referring to a JavaScript. The problem is that the script tag gets an empty namespace attribute added to it. I haven't found any information regarding this that I understand. Why does XSLT add an empty namespace?
XSL file:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:output method="xml" encoding="utf-8" />
<xsl:template match="/svg:svg">
<xsl:copy>
<script type="text/ecmascript" xlink:href="base.js" /> <!-- this tag gets a namespace attr -->
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<!-- Identity transform http://www.w3.org/TR/xslt#copying -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Check groups and add functions -->
<xsl:template match="svg:g">
<xsl:copy>
<xsl:if test="@class = 'node'">
<xsl:attribute name="onclick">node_clicked()</xsl:attribute>
</xsl:if>
<xsl:if test="@class = 'edge'">
<xsl:attribute name="onclick">edge_clicked()</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
© Stack Overflow or respective owner