[英]How to do XSLT 2.0 transform using saxon s9api? XML file to XML file
[英]How to specify output to an xml file using saxon with xslt?
我怎样才能得到output作为xml
?
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$ java -jar /usr/share/java/saxon.jar -o outputfile.xml note.xml note.xsl
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$ cat outputfile.xml
<?xml version="1.0" encoding="UTF-8"?>
Tove
Jani
Reminder
Don't forget me this weekend!
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$ cat note.xml
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$ cat note.xsl
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output media-type="text/html"/>
<xsl:mode on-no-match="shallow-copy" />
</xsl:stylesheet>
nicholas@mordor:~/xml$
指定 output 文件看起来是不够的。 也许xsl
文件对于生成xml
不正确?
从评论看来,您使用的是非常古老的 Saxon6 产品,仅支持 XSLT 1.0。 更新的版本(当前是 10.3)实现了 XSLT 3.0。
当您的样式表指定 version="3.0" 并且您的 XSLT 处理器仅支持 1.0 时,它会以“向前兼容模式”运行。 在此模式下,1.0 规范中未定义的元素和属性将被忽略。 一个这样的元素是xsl:mode
,因此您的样式表就像xsl:mode
声明不存在一样运行。 这意味着您将获得默认的“不匹配”模板行为,而不是浅拷贝,它输出源文档的文本节点并忽略元素节点。
output 如预期:
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$ rm outputfile.xml
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$ java -jar /home/nicholas/saxon/saxon-he-10.3.jar -o:outputfile.xml note.xml note.xsl
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$ cat outputfile.xml
<?xml version="1.0" encoding="UTF-8"?><note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>nicholas@mordor:~/xml$
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$ cat note.xsl
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output media-type="text/html"/>
<xsl:mode on-no-match="shallow-copy" />
</xsl:stylesheet>
nicholas@mordor:~/xml$
只是想我也许可以使用系统库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.