XOM convert XML (SVG) into XSL stylesheet

172 views Asked by At

I'm trying to turn an SVG file into an XSL stylesheet as per this article:http://www.linuxjournal.com/article/9283?page=0,0

I've tried to simply construct a new document with the svg data inserted between the XSL related elements however when I execute the method containing this code:

        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);

I get the following exception:

nu.xom.NamespaceConflictException: Prefixed elements must have namespace URIs.

If I try with the following code

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);

I get

nu.xom.IllegalNameException: 0x25 is not a legal NCName character

What am I doing wrong?

1

There are 1 answers

0
Alex Bishop On

You can’t do this:

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

You have to define the name (xsl:template) when you create the element and then add the attribute (match=""). Like this:

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