我有一个 SVG 文件,我想通过向边缘和节点添加 onclick 处理程序来扩展它。我还想添加一个引用 JavaScript 的脚本标签。问题是脚本标签添加了一个空的命名空间属性。我还没有找到任何我理解的有关此的信息。为什么 XSLT 添加一个空的名称空间?
XSL 文件:
<?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>