com.icl.saxon
Class StyleSheet

java.lang.Object
  |
  +--com.icl.saxon.trax.Processor
        |
        +--com.icl.saxon.StyleSheet
Direct Known Subclasses:
WinStyleSheet

public class StyleSheet
extends Processor

This StyleSheet class is the entry point to the Saxon XSLT Processor. This class is provided to control the processor from the command line; it also implements the TRAX Processor interface.

The XSLT syntax supported conforms to the W3C XSLT 1.0 and XPath 1.0 recommendation. Only the transformation language is implemented (not the formatting objects). Saxon extensions are documented in the file extensions.html


Field Summary
protected  Emitter messageEmitter
           
protected  NamePool namePool
           
protected  org.xml.sax.XMLReader sourceParser
           
protected  java.lang.String sourceParserName
           
protected  URIResolver sourceURIResolver
           
protected  org.xml.sax.XMLReader styleParser
           
protected  java.lang.String styleParserName
           
protected  URIResolver styleURIResolver
           
protected  TraceListener traceListener
           
 
Constructor Summary
StyleSheet()
           
 
Method Summary
protected  void badUsage(java.lang.String name, java.lang.String message)
           
protected  void doMain(java.lang.String[] args, StyleSheet app, java.lang.String name)
          Support method for main program.
 org.xml.sax.InputSource[] getAssociatedStylesheets(org.xml.sax.InputSource source, java.lang.String media, java.lang.String title, java.lang.String charset)
          Get InputSource specification(s) that are associated with the given document specified in the source param, via the xml-stylesheet processing instruction (see http://www.w3.org/TR/xml-stylesheet/), and that matches the given criteria.
 boolean getFeature(java.lang.String name)
          Look up the value of a feature.
 TemplatesBuilder getTemplatesBuilder()
          Get a TemplatesBuilder object that can process SAX events into a Templates object, if the processor supports the "http://xml.org/trax/features/sax/input" feature.
 org.xml.sax.XMLReader getXMLReader()
          Get the XML parser used for the templates.
static void main(java.lang.String[] args)
          Main program, can be used directly from the command line.
static Emitter makeMessageEmitter(java.lang.String className)
           
static TraceListener makeTraceListener(java.lang.String className)
           
static URIResolver makeURIResolver(java.lang.String className)
           
 Templates process(org.xml.sax.InputSource source)
          Process the source stylesheet into a templates object.
 void processDirectory(java.io.File sourceDir, PreparedStyleSheet sheet, java.io.File outputDir, ParameterSet params)
          Process each file in the source directory using the same supplied stylesheet
 void processDirectoryAssoc(java.io.File sourceDir, java.io.File outputDir, ParameterSet params)
          Process each file in the source directory using its own associated stylesheet
 void processFile(org.xml.sax.InputSource source, PreparedStyleSheet sheet, java.io.File outputFile, ParameterSet params)
          Process a single file using a supplied stylesheet
 void processFileAssoc(org.xml.sax.InputSource sourceInput, java.lang.String localName, java.io.File outputFile, ParameterSet params)
          Process a single source file using its associated stylesheet(s)
 Templates processFromNode(org.w3c.dom.Node node)
          Process the stylesheet from a DOM tree, if the processor supports the "http://xml.org/trax/features/dom/input" feature.
 Templates processMultiple(org.xml.sax.InputSource[] sources)
          Process a series of stylesheet inputs, treating them in import or cascade order.
protected static void quit(java.lang.String message)
          Exit with a message
 void setFeature(java.lang.String name, boolean value)
          Set the state of a feature.
 void setXMLReader(org.xml.sax.XMLReader reader)
          Set an XML parser for the stylesheet.
 
Methods inherited from class com.icl.saxon.trax.Processor
getErrorHandler, getURIResolver, newInstance, setErrorHandler, setPlatformDefaultProcessor, setURIResolver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sourceParserName

protected java.lang.String sourceParserName

styleParserName

protected java.lang.String styleParserName

sourceParser

protected org.xml.sax.XMLReader sourceParser

styleParser

protected org.xml.sax.XMLReader styleParser

sourceURIResolver

protected URIResolver sourceURIResolver

styleURIResolver

protected URIResolver styleURIResolver

messageEmitter

protected Emitter messageEmitter

traceListener

protected TraceListener traceListener

namePool

protected NamePool namePool
Constructor Detail

StyleSheet

public StyleSheet()
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Main program, can be used directly from the command line.

The format is:

java com.icl.saxon.StyleSheet [options] source-file style-file >output-file

followed by any number of parameters in the form {keyword=value}... which can be referenced from within the stylesheet.

This program applies the XSL style sheet in style-file to the source XML document in source-file.


doMain

protected void doMain(java.lang.String[] args,
                      StyleSheet app,
                      java.lang.String name)
Support method for main program. This support method can also be invoked from subclasses that support the same command line interface
Parameters:
args - the command-line arguments
app - instance of the StyleSheet class (or a subclass) to be invoked
name - name of the class, to be used in error messages

quit

protected static void quit(java.lang.String message)
Exit with a message

processDirectoryAssoc

public void processDirectoryAssoc(java.io.File sourceDir,
                                  java.io.File outputDir,
                                  ParameterSet params)
                           throws java.lang.Exception
Process each file in the source directory using its own associated stylesheet

processFileAssoc

public void processFileAssoc(org.xml.sax.InputSource sourceInput,
                             java.lang.String localName,
                             java.io.File outputFile,
                             ParameterSet params)
                      throws java.lang.Exception
Process a single source file using its associated stylesheet(s)

processDirectory

public void processDirectory(java.io.File sourceDir,
                             PreparedStyleSheet sheet,
                             java.io.File outputDir,
                             ParameterSet params)
                      throws java.lang.Exception
Process each file in the source directory using the same supplied stylesheet

processFile

public void processFile(org.xml.sax.InputSource source,
                        PreparedStyleSheet sheet,
                        java.io.File outputFile,
                        ParameterSet params)
                 throws java.lang.Exception
Process a single file using a supplied stylesheet

badUsage

protected void badUsage(java.lang.String name,
                        java.lang.String message)

makeURIResolver

public static URIResolver makeURIResolver(java.lang.String className)
                                   throws org.xml.sax.SAXException

makeTraceListener

public static TraceListener makeTraceListener(java.lang.String className)
                                       throws org.xml.sax.SAXException

makeMessageEmitter

public static Emitter makeMessageEmitter(java.lang.String className)
                                  throws org.xml.sax.SAXException

process

public Templates process(org.xml.sax.InputSource source)
                  throws ProcessorException
Process the source stylesheet into a templates object.
Overrides:
process in class Processor
Parameters:
source - An object that holds a URL, input stream, etc. for the stylesheet
Throws:
ProcessorException - May throw this during the parse when it is constructing the Templates object and fails.

processFromNode

public Templates processFromNode(org.w3c.dom.Node node)
                          throws ProcessorException
Process the stylesheet from a DOM tree, if the processor supports the "http://xml.org/trax/features/dom/input" feature.
Overrides:
processFromNode in class Processor
Parameters:
node - A DOM tree which must contain valid transform instructions that this processor understands.

processMultiple

public Templates processMultiple(org.xml.sax.InputSource[] sources)
                          throws ProcessorException
Process a series of stylesheet inputs, treating them in import or cascade order. This is mainly for support of the getAssociatedStylesheets method, but may be useful for other purposes.
Overrides:
processMultiple in class Processor
Parameters:
sources - An array of SAX InputSource objects.

getAssociatedStylesheets

public org.xml.sax.InputSource[] getAssociatedStylesheets(org.xml.sax.InputSource source,
                                                          java.lang.String media,
                                                          java.lang.String title,
                                                          java.lang.String charset)
                                                   throws ProcessorException
Get InputSource specification(s) that are associated with the given document specified in the source param, via the xml-stylesheet processing instruction (see http://www.w3.org/TR/xml-stylesheet/), and that matches the given criteria. Note that it is possible to return several stylesheets that match the criteria, in which case they are applied as if they were a list of imports or cascades.

Note that DOM2 has its own mechanism for discovering stylesheets. Therefore, there isn't a DOM version of this method.

Overrides:
getAssociatedStylesheets in class Processor
Parameters:
media - The media attribute to be matched. May be null, in which case the prefered templates will be used (i.e. alternate = no). TODO: ### if media is null, all stylesheets are returned, alternate is not used ###
title - The value of the title attribute to match. May be null.
charset - The value of the charset attribute to match. May be null.

getTemplatesBuilder

public TemplatesBuilder getTemplatesBuilder()
                                     throws ProcessorException
Get a TemplatesBuilder object that can process SAX events into a Templates object, if the processor supports the "http://xml.org/trax/features/sax/input" feature.
Overrides:
getTemplatesBuilder in class Processor
Returns:
A TemplatesBuilder object, or null if not supported.
Throws:
May - throw a ProcessorException if a TemplatesBuilder can not be constructed for some reason.

setXMLReader

public void setXMLReader(org.xml.sax.XMLReader reader)
Set an XML parser for the stylesheet. This may also be used for the XML input for the source tree, if the setXMLReader method on the Transformation method is not set.
Overrides:
setXMLReader in class Processor

getXMLReader

public org.xml.sax.XMLReader getXMLReader()
Get the XML parser used for the templates. This may also be used for the XML input for the source tree, if the setXMLReader method on the Transformation method is not set.
Overrides:
getXMLReader in class Processor
Returns:
Valid XMLReader object, or null if none has been set.

getFeature

public boolean getFeature(java.lang.String name)
                   throws org.xml.sax.SAXNotRecognizedException,
                          org.xml.sax.SAXNotSupportedException
Look up the value of a feature.
Overrides:
getFeature in class Processor
Parameters:
name - The feature name, which is a fully-qualified URI. The only names recognized are "http://xml.org/trax/features/dom/input" and "http://xml.org/trax/features/sax/input", and in both cases the value is always true.
Returns:
The current state of the feature (true or false).
Throws:
org.xml.sax.SAXNotRecognizedException - When the Processor does not recognize the feature name.
org.xml.sax.SAXNotSupportedException - When the Processor recognizes the feature name but cannot determine its value at this time.

setFeature

public void setFeature(java.lang.String name,
                       boolean value)
                throws org.xml.sax.SAXNotRecognizedException,
                       org.xml.sax.SAXNotSupportedException
Set the state of a feature.
Overrides:
setFeature in class Processor
Parameters:
name - The feature name, which is a fully-qualified URI. The only names recognized are "http://xml.org/trax/features/dom/input" and "http://xml.org/trax/features/sax/input", and in both cases the only permitted value is true.
state - The requested state of the feature (true or false).
Throws:
org.xml.sax.SAXNotRecognizedException - When the Processor does not recognize the feature name.
org.xml.sax.SAXNotSupportedException - When the Processor recognizes the feature name but cannot set the requested value.