【问题标题】:XOM convert XML (SVG) into XSL stylesheetXOM 将 XML (SVG) 转换为 XSL 样式表
【发布时间】:2013-09-06 00:12:30
【问题描述】:

我正在尝试按照本文将 SVG 文件转换为 XSL 样式表:http://www.linuxjournal.com/article/9283?page=0,0

我尝试简单地构造一个新文档,其中插入了 XSL 相关元素之间的 svg 数据,但是当我执行包含此代码的方法时:

        Document input=builder.build(sourcefile);
        Element styletags=new Element("xsl:stylesheet",
                                      "http://www.w3.org/1999/XSL/Transform");
        styletags.appendChild(new Element("xsl:template%20match=\"/\""));
        styletags.appendChild(input);
        Document result=new Document(styletags);

我得到以下异常:

nu.xom.NamespaceConflictException:前缀元素必须具有命名空间 URI。

如果我尝试使用以下代码

Element xsl=new Element("template%20match=\"/\""); xsl.addNamespaceDeclaration("xsl","http://www.w3.org/1999/XSL/Transform"); Element styletags=new Element("stylesheet"); styletags.addNamespaceDeclaration("xsl","http://www.w3.org/1999/XSL/Transform"); styletags.appendChild(xsl); styletags.appendChild(input);

我明白了

nu.xom.IllegalNameException: 0x25 不是合法的 NCName 字符

我做错了什么?

【问题讨论】:

    标签: xml xslt xom


    【解决方案1】:

    你不能这样做:

    new Element("xsl:template%20match=\"/\"")
    

    您必须在创建元素时定义名称 (xsl:template),然后添加属性 (match="")。像这样:

    Element template = new Element("xsl:template", "http://www.w3.org/1999/XSL/Transform");
    template.addAttribute(new Attribute("match", ""));
    

    【讨论】:

      猜你喜欢
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-19
      • 1970-01-01
      • 2017-11-06
      • 1970-01-01
      • 2012-04-03
      • 2014-07-30
      相关资源
      最近更新 更多