Preloading shared reference documents

An option is available (Feature.PRE_EVALUATE_DOC_FUNCTION) to indicate that calls to the doc() or document() functions with constant string arguments should be evaluated when a query or stylesheet is compiled, rather than at run-time. This option is intended for use when a reference or lookup document is used by all queries and transformations. Using this option has a number of effects:

  1. The URI is resolved using the compile-time URIResolver rather than the run-time URIResolver.

  2. The document is loaded into a document pool held by the Configuration, whose memory is released only when the Configuration itself ceases to exist.

  3. All queries and transformations using this document share the same copy.

  4. Any updates to the document that occur between compile-time and run-time have no effect.

The option is selected by using Configuration.setConfigurationProperty() or TransformerFactory.setAttribute() with the property name Feature.PRE_EVALUATE_DOC_FUNCTION.name. This option is not available from the command line because it has no useful effect with a single-shot compile-and-run interface.

This option has no effect if the URI supplied to the doc() or document() function includes a fragment identifier.

It is also possible to preload a specific document into the shared document pool from the Java application by using the call config.getGlobalDocumentPool().add(doc, uri). When the doc() or document() function is called, the shared document pool is first checked to see if the requested document is already present. The DocumentPool object also has a discard() method which causes the document to be released from the pool.