0
我有一个SVG文件,我想通过将onclick处理程序添加到边和节点来扩展它。我也想添加一个引用JavaScript的脚本标签。问题是脚本标签获得了一个空的名称空间属性添加到它。 我还没有找到任何有关我了解的信息。为什么XSLT添加一个空的名称空间?SVG的XSL转换将namespace属性添加到新标记
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>
谢谢您的解决方案和链接。 – Steve 2010-03-29 17:20:36