Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt SVG的XSL转换将名称空间属性添加到新标记中_Xslt_Svg_Xml Namespaces - Fatal编程技术网

Xslt SVG的XSL转换将名称空间属性添加到新标记中

Xslt SVG的XSL转换将名称空间属性添加到新标记中,xslt,svg,xml-namespaces,Xslt,Svg,Xml Namespaces,我有一个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文件,我想通过向边和节点添加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>

节点_单击()
边_单击()

未固定的文本结果元素
脚本
位于默认名称空间中,在本例中没有名称空间。在结果文档中,此元素通过
xmlns=”“
显式放置在无命名空间中

第6.2节规定:

默认设置中的属性值 命名空间声明可能为空。 在 声明的范围,有哪些 没有默认名称空间

如果希望它是默认名称空间中的
svg:script
,请将svg名称空间作为样式表的默认名称空间。您仍然需要该名称空间的名称空间前缀

<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"
    xmlns="http://www.w3.org/2000/svg">

感谢您提供的解决方案和链接。