Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2013, 01:47 PM
Authorized User
 
Join Date: Nov 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default Adding auxiliar xml to global document pool

Hi all,

I´m trying to load a xml doc in Saxon´s cache in order to access it inside my xslt with a document() function.

This is my Java code:

Code:
Source xsltTarget = new StreamSource(xsltInput);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xsltTarget);
Controller controller = (net.sf.saxon.Controller) transformer;
Configuration configuration = controller.getConfiguration();

configuration.setConfigurationProperty(FeatureKeys.PRE_EVALUATE_DOC_FUNCTION, Boolean.TRUE);

Source source = r.resolve("C:/xml/mydocument.xml", "C:/xml");
DocumentInfo newdoc = configuration.buildDocument(source);

configuration.getGlobalDocumentPool().add(newdoc, "C:/xml/mydocument.xml");

streamSource = new StreamSource(new StringReader(xml));
resultTarget = new StreamResult(new StringWriter());
transformer.transform(streamSource, resultTarget);
Then, in my xslt, I want to define my document variable:

<xsl:variable name="documentPath" select="'C:/xml/mydocument.xml'"/>
<xsl:variable name="doc" select="document($documentPath)"/>

I don´t know whether I´m setting the URI and baseURI parameters correctly in my Java code, and also don´t know how to reference it inside my xslt (does it work just with document('C:/xml/mydocument.xml')?), but I think Saxon is not pre-caching anything.

I´d appreciate any help. I can´t find a complete example in the Internet.

Regards
 
Old November 21st, 2013, 02:30 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First, if you have product-specific questions on Saxon, please ask them on the forum at plan.saxonica.io. There's no guarantee we will spot the question here.

I don't think it's advisable to mess with Saxon's internal cache in this way. The APIs are unlikely to be stable.

The right approach is to create your own pool of documents as a map from URIs to document nodes (which you can construct either using the s9api DocumentBuilder, or using Configuration.buildDocument()), and then register a URIResolver which responds to doc() requests by fetching the document from this pool.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old November 22nd, 2013, 06:59 AM
Authorized User
 
Join Date: Nov 2012
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Excuse me Michael, I´ll move this question and my new answer to there.

Thank you anyway





Similar Threads
Thread Thread Starter Forum Replies Last Post
Build XML document from two XML inputs daplex XSLT 0 September 27th, 2013 01:10 PM
Create an XML document using JAXP and XML fragments. WilliamYou XML 2 October 29th, 2012 03:44 PM
Adding an elements to existing xml document crashbandicoot BOOK: Beginning PHP 5.3 0 January 12th, 2012 05:51 PM
Split xml file with result document and javax.xml.transform.Transformer. nisargmca XSLT 3 January 12th, 2010 06:26 AM
Adding a new Node to existing XML document Lupus81 XML 3 August 4th, 2009 04:57 PM





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