<s1 title="XSL API">

<p>Applying XSL is a multi-step process:</p>

<ol>
<li>Create a javax.xml.transform.TransformerFactory
<li>Parse a javax.xml.transform.Templates (Stylesheet)
<li>Create a javax.xml.transform.Transformer
<li>Set any XSL variables
<li>Create a javax.xml.transform.Source for the input.
<li>Create a javax.xml.transform.Result for the output.
<li>Call transform() to transform the input to the output.
</ol>

<p>The transformers let you select the output format appropriate for
your application: output stream, string, or node.  In addition, each
transformer instance lets you set XSL parameters (i.e. parameters set
by xsl:param.)</p>

<example title="Java API for XSL transform">

import java.io.*;

import javax.xml.transform.*;
import javax.xml.transform.stream.*;

import com.caucho.vfs.*;
import com.caucho.xml.*;
import com.caucho.xsl.*;

public class Test {
  public static void main(String []args)
    throws Exception
  {
    TransformerFactory factory = TransformerFactory.newInstance();

    StreamSource xslSource = new StreamSource("test.xsl");
    // Load the stylesheet.  If it's already compiled, Resin will just
    // load the compiled class.  More sophisticated application will
    // cache the Templates object.
    Templates stylesheet = factory.newTemplates(xslSource);

    // Create a transformer.  This could also be called from a
    // cached Templates object.  The Transformer should not be cached.
    Transformer transformer = stylesheet.newTransformer();

    // Sets a parameter for the xsl:param "source"
    transformer.setParameter("source", "java");

    // The source is a file.
    StreamSource source = new StreamSource("test.xml");

    // The result is a file.
    StreamResult result = new StreamResult("test.html");

    transformer.transform(source, result);
  }
}
</example>

<s2 title="Configuring JAXP for Xalan">

<p>JAXP is a standard interface which supports pluggable XML and XSL
implementations.  JAXP selects the parser based on
system properties.  You can set the properties to select
a different parser than the default one.</p>

<deftable title="JAXP Properties for Resin">
<tr><th>system property<th>Resin value
<tr><td>javax.xml.parsers.DocumentBuilderFactory
    <td>com.caucho.xml.parsers.XmlDocumentBuilderFactory
<tr><td>javax.xml.parsers.SAXParserFactory
    <td>com.caucho.xml.parsers.XmlSAXParserFactory
<tr><td>javax.xml.transform.TransformerFactory
    <td>com.caucho.xsl.Xsl
</deftable>

<deftable title="JAXP Properties for Xalan/Xerces">
<tr><th>system property<th>Xerces value
<tr><td>javax.xml.parsers.DocumentBuilderFactory
    <td>org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
<tr><td>javax.xml.parsers.SAXParserFactory
    <td>org.apache.xerces.jaxp.SAXParserFactoryImpl
<tr><td>javax.xml.transform.TransformerFactory
    <td>org.apache.xalan.processor.TransformerFactoryImpl
</deftable>

<p>The resin.conf and web.xml will let you configure system properties on
a per-application basis.</p>

</s2>

<s2 title="Summary">

<ul>
<li><var/Transformers/> select different output formats.
</ul>

</s2>
</s1>
