<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="using-xsl" page="compiling" subpage=""/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: Compiling a Stylesheet</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Compiling a Stylesheet"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Compiling a Stylesheet</h1>
      <p>Saxon allows a compiled stylesheet (a <code>Templates</code> object) 
to be saved to disk as a file.
The transformation can then be run using this compiled stylesheet by using the -c option
to the command <code>java net.sf.saxon.Transform</code>.</p>
      <p><i>The facility to compile the stylesheet is available only under Saxon-EE, but the compiled stylesheet can 
  be executed under <code>Saxon-HE</code>. The facility is not available on the .NET platform.</i></p>
      <p>The actual compilation of the stylesheet can be achieved using the command
<code>java com.saxonica.CompileStylesheet</code>. The format of the command is:</p>
      <p class="command">java  com.saxonica.CompileStylesheet 
  [options]   stylesheet   output   [ <i>params...</i>]</p>
      <p>The options available are a subset of the options for running a transformation, described above. The
most relevant options are <code>-t</code> (give progress messages), <code>-u</code> (stylesheet argument is a URI, not a filename), <code>-r</code>
(specify a URIResolver for use at compile time), <code>-y</code> (specify an XML parser for parsing the source 
stylesheet), <code>-xml:1.1</code> (enable XML 1.1), <code>-init</code> (provide an initialization class),
         and <code>-config:filename</code> (supply a configuration file). For a full list, use the <code>-?</code> option.</p>
      <p>There are some restrictions that apply to stylesheet compilation:</p>
      <ul>
         <li content="para">
            <p>Stylesheet compilation is not currently supported for schema-aware stylesheets, specifically, for stylesheets
that contain an <code>&lt;xsl:import-schema&gt;</code> declaration.</p>
         </li>
         <li content="para">
            <p>Stylesheet compilation is not currently supported for stylesheets that make calls on
the extension functions <code>saxon:evaluate()</code> or <code>saxon:expression()</code>, because these require run-time
access to information that is not preserved by compilation.</p>
         </li>
         <li content="para">
            <p>Stylesheets that use a <code>&lt;saxon:import-query&gt;</code> declaration cannot be compiled.</p>
         </li>
         <li content="para">
            <p>A compiled stylesheet can be executed only by the same Saxon release as was used to compile it.</p>
         </li>
         <li content="para">
            <p>Stylesheet compilation is not supported on the .NET platform.</p>
         </li>
      </ul>
      <p>You can use any file extension for the compiled stylesheet, I generally use .sxx (Saxon XSLT executable).
The file actually contains the Java serialization of a data structure that is then used at run-time to
drive the transformation process. As an alternative to using the <code>net.sf.saxon.Compile</code> command
from the command line, you can use the Java serialization API directly, to write the <code>net.sf.saxon.Templates</code>
object to an <code>ObjectOutputStream</code>.</p>
      <p>Running a compiled stylesheet is directly supported only from the command line. If you want to embed
  this capability in your own application, you can copy the relevant code from the source of the
  <code>net.sf.saxon.Transform</code> command. You need to be aware, however, that this code creates a new 
  <code>NamePool</code> and modifies the <code>Configuration</code> to use it, which will disrupt any other
  applications sharing the same <code>Configuration</code>. It is the responsibility of the application to ensure
  that a compiled stylesheet runs in a dedicated <code>Configuration</code>,
  rather than sharing a Configuration object with other transformations.</p>
      <p><i>The term "compile" is stretching a point. The executable that is produced does not contain
machine instructions, or even interpreted Java bytecode. It contains instructions in the form of 
a data structure that Saxon itself can interpret. Note that the format of compiled stylesheets is
unlikely to be stable from one Saxon release to the next.</i></p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="xsltfromant.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>