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