Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用saxon和xslt指定xml文件的输出?_Java_Xml_Linux_Xslt_Saxon - Fatal编程技术网

Java 如何使用saxon和xslt指定xml文件的输出?

Java 如何使用saxon和xslt指定xml文件的输出?,java,xml,linux,xslt,saxon,Java,Xml,Linux,Xslt,Saxon,如何获取asxml 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-

如何获取as
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$ 
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
托弗
贾尼
提醒
这个周末别忘了我!
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$cat note.xml
托弗
贾尼
提醒
这个周末别忘了我!
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$cat note.xsl
nicholas@mordor:~/xml$

指定输出文件不足。也许
xsl
文件在生成
xml
时不正确?

根据注释,您似乎正在使用非常古老的Saxon6产品,它只支持XSLT 1.0。最近的版本(当前版本为10.3)实现了XSLT3.0

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$ 
当样式表指定version=“3.0”且XSLT处理器仅支持1.0时,它将在“向前兼容模式”下运行。在此模式下,将忽略1.0规范中未定义的元素和属性。其中一个元素是
xsl:mode
,因此样式表运行时就好像没有
xsl:mode
声明一样。这意味着不是浅复制,而是默认的“不匹配”模板行为,它输出源文档的文本节点并忽略元素节点。

按预期输出:

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$ 
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
托弗
贾尼
提醒
这个周末别忘了我!
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$
nicholas@mordor:~/xml$cat note.xsl
nicholas@mordor:~/xml$

我想我可以使用系统库。

我想Saxon 6想要
-o outputfile.xml
而不是
-o:outputfile.xml
。但是我不知道为什么您希望将Saxon 6与XSLT 3一起使用,您至少需要Saxon 9.8才能支持XSLT 3。正如您所说,它是
-o outputfile.xml
,thx。我将尝试使用xslt 2.x,它输出元素内容,而不是实际的
xml
。正如我所说的,不要指望xslt 3的
等功能与xslt 1或2处理器配合使用,Saxon 9.8(至少对他来说)是W3C在2017年指定的第一个支持xslt 3的版本,对于PE或EE,您可能会在早期的Saxon版本中获得3.0支持,但基于一些中间工作草案。