How to use the about: protocol for HTML5 in XSLT processors

The HTML5 project indicates (at least for the time being) that the about:legacy-compat can be used for documents that rely on an XML-compatible doctype (which <!DOCTYPE html> not).

So, I have a package of HTML5-validating XML files that start with:

 <!DOCTYPE html SYSTEM "about:legacy-compat"> 

Unfortunately, when I use such an XHTML5 document with any XSLT processor, such as Xalan or Saxon, they naturally try to resolve the (unsolvable) URI.

Is there a way to get them to ignore the URI or fake it under the hood? An attempt to solve this occurs at the beginning of these documents, therefore, for example, Saxon -dtd:off has no effect.

Edit: low-level approach sed -n '2,$p' <htmlfile> | otherapp sed -n '2,$p' <htmlfile> | otherapp , unfortunately, only works until I start using the XPath document() function to load another XHTML5 file.

Edit 2: I played with XML directories and made them work with both Saxon and Xalan. However, I always get

 java.net.MalformedURLException: unknown protocol: about 

Well, this is not surprising, but how can I get around this? The URL should never be parsed, just throw it away.

+4
source share
1 answer

Put this Java file in $ somepath / foo / about /

 package foo.about; import java.io.IOException; import java.io.InputStream; import java.io.StringBufferInputStream; import java.net.URL; import java.net.URLConnection; public class Handler extends java.net.URLStreamHandler { @Override protected URLConnection openConnection(URL url) throws IOException { URLConnection res = new URLConnection(url) { @Override public void connect() throws IOException { connected = true; } @Override public InputStream getInputStream() throws IOException { return new StringBufferInputStream("<!ELEMENT html ANY>"); } }; return res; } } 

Now go to $ somepath and compile it:

 javac foo/about/Handler.java 

Add the following arguments to the JVM when calling Saxon:

 -Djava.protocol.handler.pkgs=foo -cp"$somepath" 

Here is a modified shell script script (for * nix system, but it is very similar to Windows):

 #!/bin/sh exec java -Djava.protocol.handler.pkgs=foo -classpath /usr/share/java/saxonb.jar:"$somepath" net.sf.saxon.Transform " $@ " 

You might want to adapt using the local saxonb-xslt script file if it doesn't work.

+4
source

All Articles