Class XsltCompiler


  • public class XsltCompiler
    extends java.lang.Object
    An XsltCompiler object allows XSLT 2.0 stylesheets to be compiled. The compiler holds information that represents the static context for the compilation.

    To construct an XsltCompiler, use the factory method Processor.newXsltCompiler() on the Processor object.

    An XsltCompiler may be used repeatedly to compile multiple queries. Any changes made to the XsltCompiler (that is, to the static context) do not affect queries that have already been compiled. An XsltCompiler may be used concurrently in multiple threads, but it should not then be modified once initialized.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected XsltCompiler​(Processor processor)
      Protected constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      XsltExecutable compile​(javax.xml.transform.Source source)
      Compile a stylesheet.
      javax.xml.transform.ErrorListener getErrorListener()
      Get the ErrorListener being used during this compilation episode
      javax.xml.transform.URIResolver getURIResolver()
      Get the URIResolver to be used during stylesheet compilation.
      boolean isCompileWithTracing()
      Ask whether trace hooks are included in the compiled code.
      void setCompileWithTracing​(boolean option)
      Set whether trace hooks are to be included in the compiled code.
      void setErrorListener​(javax.xml.transform.ErrorListener listener)
      Set the ErrorListener to be used during this compilation episode
      void setURIResolver​(javax.xml.transform.URIResolver resolver)
      Set the URIResolver to be used during stylesheet compilation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XsltCompiler

        protected XsltCompiler​(Processor processor)
        Protected constructor
        Parameters:
        processor - the Saxon processor
    • Method Detail

      • setURIResolver

        public void setURIResolver​(javax.xml.transform.URIResolver resolver)
        Set the URIResolver to be used during stylesheet compilation. This URIResolver, despite its name, is not used for resolving relative URIs against a base URI; it is used for dereferencing an absolute URI (after resolution) to return a Source representing the location where a stylesheet module can be found.

        This URIResolver is used to dereference the URIs appearing in xsl:import, xsl:include, and xsl:import-schema declarations. It is not used at run-time for resolving requests to the document() or similar functions.

        Parameters:
        resolver - the URIResolver to be used during stylesheet compilation.
      • getURIResolver

        public javax.xml.transform.URIResolver getURIResolver()
        Get the URIResolver to be used during stylesheet compilation.
        Returns:
        the URIResolver used during stylesheet compilation. Returns null if no user-supplied URIResolver has been set.
      • setErrorListener

        public void setErrorListener​(javax.xml.transform.ErrorListener listener)
        Set the ErrorListener to be used during this compilation episode
        Parameters:
        listener - The error listener to be used. This is notified of all errors detected during the compilation.
      • getErrorListener

        public javax.xml.transform.ErrorListener getErrorListener()
        Get the ErrorListener being used during this compilation episode
        Returns:
        listener The error listener in use. This is notified of all errors detected during the compilation. Returns null if no user-supplied ErrorListener has been set.
      • setCompileWithTracing

        public void setCompileWithTracing​(boolean option)
        Set whether trace hooks are to be included in the compiled code. To use tracing, it is necessary both to compile the code with trace hooks included, and to supply a TraceListener at run-time
        Parameters:
        option - true if trace code is to be compiled in, false otherwise
      • isCompileWithTracing

        public boolean isCompileWithTracing()
        Ask whether trace hooks are included in the compiled code.
        Returns:
        true if trace hooks are included, false if not.
      • compile

        public XsltExecutable compile​(javax.xml.transform.Source source)
                               throws SaxonApiException
        Compile a stylesheet.

        Note: the term "compile" here indicates that the stylesheet is converted into an executable form. There is no implication that this involves code generation.

        The source argument identifies the XML document holding the principal stylesheet module. Other modules will be located relative to this module by resolving against the base URI that is defined as the systemId property of the supplied Source.

        The following kinds of Source are recognized:

        • StreamSource, allowing the stylesheet to be supplied as a URI, as a File, as an InputStream, or as a Reader
        • SAXSource, allowing the stylesheet to be supplied as a stream of SAX events from a SAX2-compliant XML parser (or any other source of SAX events)
        • DOMSource, allowing the stylesheet to be supplied as a DOM tree. This option is available only if saxon9-dom.jar is on the classpath.
        • Document wrappers for XOM, JDOM, or DOM4J trees, provided the appropriate support libraries are on the classpath
        • A Saxon NodeInfo, representing the root of a tree in any of the native tree formats supported by Saxon
        • An XdmNode representing the document node of the stylesheet module
        Parameters:
        source - Source object representing the principal stylesheet module to be compiled
        Returns:
        an XsltExecutable, which represents the compiled stylesheet.
        Throws:
        SaxonApiException - if the stylesheet contains static errors or if it cannot be read. Note that the exception that is thrown will not contain details of the actual errors found in the stylesheet. These will instead be notified to the registered ErrorListener. The default ErrorListener displays error messages on the standard error output.