Re: How to process Altova XSLT-Word 2007+ with Saxon-EE 10.3 for Java

Michael Kay <[email protected]> Tue, 27 Apr 2021 09:04:34 +0100
Newsgroups gmane.text.xml.saxon.help
Message-ID <[email protected]>
When xsl:result-document/@href is a relative URI, the rules for XSLT 2.0 say that it is interpreted as being relative to the "base output URI" of the transformation. The problem is that you have given the principal output of the transformation as a StreamResult with no known URI, so the base output URI is unknown/absent. The only change you need to make to your Java code is to supply a URI:

> StreamResult out = new StreamResult(os, "file:///c:/outputdir/");

and the xsl:result-document output will then go into files within c:/outputdir/. It should be possible to specify a "jar" URI here to have output files written directly into a JAR or zip file, but I wouldn't be confident that all possibilities are tested.

As for your attempt to produce a .docx file directly from the command line, this isn't something Saxon supports. It's something you can do from a Java application (though I would need to do some thinking to work out exactly how), but not from the command line.

Michael Kay
Saxonica

> On 27 Apr 2021, at 08:44, <info-vDJW/ys76H/[email protected]> <info-vDJW/ys76H/[email protected]> wrote:
> 
> Hello Saxon gurus, I’m a Saxon novice. I have just basic knowledge of XSLT 1.0 and Java. I hope my question is not too basic.
> 
> I created my first project in Altova StyleVision. Results are two XSLT-s: IRtest1-RTF.xslt (XSLT-RTF) and  IRtest1-DOCX.xslt (XSLT-Word 2007+). Both works fine in StyleVision. 
> I create Java Servlet with Saxon EE 10.3. Servlet works fine with XSLT 2.0 IRtest1-RTF.xslt but does not work with XSLT 3.0 IRtest1-DOCX.xslt. Main part of straightforward Java code is:
>  
> TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl(); 
> StreamSource xslStream = new StreamSource(new ByteArrayInputStream(inputXSL.getBytes(encoding)));
> Transformer transformer = factory.newTransformer(xslStream);
> StreamSource in = new StreamSource(new ByteArrayInputStream(dataXML.getBytes(encoding)));
> ByteArrayOutputStream os = new ByteArrayOutputStream();
> StreamResult out = new StreamResult(os);
> transformer.transform(in, out);
>  
> Last sentence fails with:
> Error in xsl:result-document/@href on line 283 column 87 
>   SXRD0002  The system identifier of the principal output file is unknown 
>  
> Line 283 of IRtest1-DOCX.xslt XSLT is: 
> <xsl:result-document href="{$altova:sPrefix}word/document.xml" format="zip-format">
>  
> I guess I should use Xslt30Transformer and setBaseOutputURI method: (https://www.saxonica.com/html/documentation10/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#setBaseOutputURI-java.lang.String- <https://www.saxonica.com/html/documentation10/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#setBaseOutputURI-java.lang.String-> ), but I do not know how to change my Java code? 
> Is it possible to use Altova XSLT-Word 2007+ with SaxonEE?
>  
> Also following command line on Windows 10 does not work as expected (full paths omitted for clarity) :
> java -jar saxon-ee-10.3.jar -xsl:IRtest1-DOCX.xslt input.xml -o:IRtest1-DOCX.docx
>  
> Instead of getting DOCX output I get folders _rels, docProps, word with files and file [Content_Types].xml. If I manually zipped them into IRtest1-DOCX.docx, Word can open docx successfully.  
> Thanks for any help.
>  
> Regards
> Miro
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/ <http://saxon.markmail.org/>
> [email protected] <mailto:[email protected]>
> https://lists.sourceforge.net/lists/listinfo/saxon-help <https://lists.sourceforge.net/lists/listinfo/saxon-help>

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help