0

How can I get the output 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$ 

Specifying an output file looks to be insufficient. Perhaps the xsl file is incorrect for generating xml?

  • 1
    I think Saxon 6 wants `-o outputfile.xml` instead of `-o:outputfile.xml`. But I have no idea why you expect to use Saxon 6 with XSLT 3, you need at least Saxon 9.8 for XSLT 3 to be supported. – Martin Honnen Dec 03 '20 at 14:37
  • it was `-o outputfile.xml` as you said, thx. I'll try with xslt 2.x, it outputs the element content rather than actual `xml`. – Nicholas Saunders Dec 03 '20 at 14:40
  • 1
    As I said, don't expect XSLT 3 features like `` to work with an XSLT 1 or 2 processor, Saxon 9.8 (at least for HE) is the first version to support XSLT 3 as specified by the W3C in 2017, for PE or EE you might get 3.0 support in earlier Saxon versions, but based on some intermediary working draft. – Martin Honnen Dec 03 '20 at 14:44

2 Answers2

1

From the comments, it seems you are using the very ancient Saxon6 product, which only supports XSLT 1.0. More recent versions (the current is 10.3) implement XSLT 3.0.

When your stylesheet specifies version="3.0" and your XSLT processor only supports 1.0, then it runs in "forwards compatibility mode". In this mode, elements and attributes that weren't defined in the 1.0 specification are ignored. One such element is xsl:mode, so your stylesheet runs as if the xsl:mode declaration were not there. This means that instead of shallow-copy, you get the default "no match" template behaviour, which outputs the text nodes of the source document and ignores the element nodes.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

output as expected:

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$ 

Just thought I might be able to use the system libraries.