p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Accessing secondary result documents from Java (http://p2p.wrox.com/showthread.php?t=71815)

maikm December 15th, 2008 08:59 AM

Accessing secondary result documents from Java
 
Hi folks (Hi Michael ;~)

I have one source XML and several destination XML documents. I'm generating the main result document with Saxon B9, and the XSLT contains something like the following section:

Code:

<xsl:result-document href="secondary.xml">
    (...some code...)
</xsl:result-document>

The calling Java code looks like this:
Code:

    String path = workdir.getAbsolutePath();
    DOMSource domSource = new DOMSource( domDocument, path );
    xslttrans.setSource( domSource );
    Serializer ser = new Serializer();
    ser.setOutputFile( new File( path + "/" + "document.xml" ) );
    xslttrans.setDestination( ser );
    xslttrans.transform();

I get the main result document, but I can't figure out how to access the secondary file. It's not being written at the same directory as the main output, and I can't figure out how to set the base URI that might be needed for it to do that. Any hints anyone?

Thanks
Maik

mhkay December 15th, 2008 09:48 AM

First, an aside: using a DOMSource with Saxon is really inefficient and you should only do it if you already have the source in the form of a DOM. Much better to let Saxon build the tree in its own native format.

Second point: you're asking a question here that's very specific to Saxon. The best place to do that is on the saxon-help mailing list or forum which you can reach via the saxon project on sourceforge. The advantage of doing that is that users can help each other much better if they all meet in the same place.

In theory the output files should be written to the same directory as the principal output. I'll try to run a test similar to your code to see if I can reproduce the problem.

You should be able to see where the files are being written by using

processor.setProperty(FeatureKeys.TIMING, "true")

This is equivalent to the -t option on the command line.

mhkay December 15th, 2008 10:31 AM

I've raised a bug for this at https://sourceforge.net/tracker2/?fu...72&atid=397617 and a patch is in Subversion. I can't see an obvious workaround other than setting an absolute URI in the xsl:result-document/@href attribute. The files are actually being written to the current working directory.

maikm December 15th, 2008 11:14 AM

Thanks for the blazingly fast support, Michael! [:)]

I made a workaround by supplying an attribute to the root note with the workdir used, and prefixed the href path with that: works.

Quote:

Originally Posted by mhkay (Post 231587)
First, an aside: using a DOMSource with Saxon is really inefficient and you should only do it if you already have the source in the form of a DOM. Much better to let Saxon build the tree in its own native format.

I'm not reading an existing xml file, the document is built dynamically. It's there as a org.w3c.dom.Document, so I felt this was the natural way to go. If something other is more efficient, can you give me a two-liner of how to do that?

I'll join the saxon list right away. I didn't really know how saxon-specific the question was, or even whether the problem was in XSLT, Java or Saxon.

Quote:

processor.setProperty(FeatureKeys.TIMING, "true")
I suppose you meant processor.setConfigurationProperty().

Thanks again
Maik


All times are GMT -4. The time now is 10:13 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.