如何使用“约:” XSLT处理器中的HTML5协议 [英] How to use the "about:" protocol of HTML5 in XSLT processors
问题描述
HTML5草案指定(目前至少),关于:legacy-compat 的URI 可用于依赖符合XML的doctype的文档(
<!DOCTYPE html>
不是。)
The HTML5 draft specifies (at the moment at least), that the URI about:legacy-compat
can be used for documents, that rely on an XML conforming doctype (which <!DOCTYPE html>
isn't).
所以我碰巧有一堆HTML5验证XML文件,开头是:
So I happen to have a bundle of HTML5-validating XML files, that start with:
<!DOCTYPE html SYSTEM "about:legacy-compat">
不幸的是,当我将这样的XHTML5文档与Xalan或Saxon等XSLT处理器一起使用时,他们自然会尝试解决(不可解析的)URI。
Unfortunately, when I use such an XHTML5 document with any XSLT processor like Xalan or Saxon, they naturally try to resolve the (unresolvable) URI.
有没有办法让他们忽略URI或者在引擎盖下进行虚假解析?试图解决它的问题发生在这些文档的早期,所以例如Saxon的 -dtd:off
开关在这里没有效果。
Is there any way to bring them into ignoring the URI or faux-resolving it under the hood? The try to resolve it happens early in these documents, so for example Saxon's -dtd:off
switch has no effect here.
编辑:低级方法 sed -n'2,$ p'< htmlfile> | otherapp
遗憾的是只有在我开始使用 document()
XPath函数加载另一个XHTML5文件之后才能工作。
The low-level approach sed -n '2,$p' <htmlfile> | otherapp
unfortunately only works until I start to use the document()
XPath function to load another XHTML5 file.
编辑2:我玩过 XML目录让他们与Saxon和Xalan合作。但是,我总是得到一个
Edit 2: I played around with XML catalogs and got them to work with both Saxon and Xalan. However, then I get always a
java.net.MalformedURLException: unknown protocol: about
嗯,这并不奇怪,但我怎么能绕过这个呢?永远不应该解析URL,只是扔掉。
Well, it's not surprising, but how can I circumvent this? The URL should never be parsed, just thrown away.
推荐答案
将这个Java文件放入$ somepath / foo / about /
Put this Java file into $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;
}
}
现在进入$ somepath并编译它:
Now go in $somepath and compile it:
javac foo/about/Handler.java
调用Saxon时,将以下参数添加到JVM:
Add the following arguments to the JVM when calling Saxon:
-Djava.protocol.handler.pkgs=foo -cp"$somepath"
这是一个修改过的shell脚本脚本(适用于* nix)系统,但它与Windows非常相似):
Here is a modified shell script script (for *nix system but it it very similar for Windows):
#!/bin/sh
exec java -Djava.protocol.handler.pkgs=foo -classpath /usr/share/java/saxonb.jar:"$somepath" net.sf.saxon.Transform "$@"
如果它不起作用,您可能需要使用本地saxonb-xslt脚本进行调整。
You may want to adapt using your local saxonb-xslt script if it doesn't work.
这篇关于如何使用“约:” XSLT处理器中的HTML5协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!