public class XSLTUtilities
extends java.lang.Object
This file uses Saxon, the XSLT and XQuery Processor http://saxon.sourceforge.net.
Between Java 1.4.x and Java 1.5, Xalan was removed from the jar files that are shipped. Since Caltrop uses Saxon anyway, we now use Saxon here as well.
Modifier and Type | Method and Description |
---|---|
static void |
main(java.lang.String[] args)
Apply XSL transforms to an input file and generate an output file.
|
static org.w3c.dom.Document |
parse(java.lang.String filename)
Parse an XML document using Saxon.
|
static void |
setExportDTD(boolean exportDTD)
Set the flag indicating whether to export DTD specification when
transforming XML files.
|
static java.lang.String |
toString(org.w3c.dom.Document document)
Given a Document, generate a String.
|
static org.w3c.dom.Document |
transform(org.w3c.dom.Document inputDocument,
java.util.List xslFileNames)
Transform a document by applying a list of transforms.
|
static org.w3c.dom.Document |
transform(org.w3c.dom.Document inputDocument,
java.lang.String xslFileName)
Transform a document.
|
static void |
transform(java.lang.String input,
java.io.FileWriter fileWriter,
java.util.List xslFileNames)
Transform a file by applying a list of XSL transforms.
|
public static void main(java.lang.String[] args) throws java.lang.Exception
Example use:
java -classpath $PTII ptolemy.util.XSLTUtilities $PTII/ptolemy/hsif/demo/SwimmingPool/SwimmingPool.xml \ $PTII/ptolemy/hsif/xsl/GlobalVariablePreprocessor.xsl \ exportMoMLDTD \ /tmp/SwimmingPool_1.xml
args
- At least three arguments:
java.lang.Exception
- If there are problems with the transform.public static org.w3c.dom.Document parse(java.lang.String filename) throws javax.xml.parsers.ParserConfigurationException, java.io.IOException
filename
- The file name of the xml file to be read in
The filename is passed to org.xml.sax.InputSource(String),
so it may be a file name or a URL.javax.xml.parsers.ParserConfigurationException
- If there is a problem
creating the DocumentBuilder.java.io.IOException
- If the filename could not be parsed.public static void setExportDTD(boolean exportDTD)
exportDTD
- True for export DTD, false for not.public static java.lang.String toString(org.w3c.dom.Document document) throws javax.xml.transform.TransformerException, java.io.IOException
document
- The document to be converted to a string.javax.xml.transform.TransformerException
- If there is a
a problem creating a new Transformer or parser.java.io.IOException
- If there is a problem closing the output
stream.public static org.w3c.dom.Document transform(org.w3c.dom.Document inputDocument, java.lang.String xslFileName) throws javax.xml.transform.TransformerException, java.io.IOException
inputDocument
- The Document to be transformedxslFileName
- The file name of the xsl file to be used.
If the file cannot be found, then we look up the file in the classpath.javax.xml.transform.TransformerException
- If there is a problem with the
transform.java.io.IOException
- If there is a problem finding the
transform file.public static org.w3c.dom.Document transform(org.w3c.dom.Document inputDocument, java.util.List xslFileNames) throws javax.xml.transform.TransformerException, java.io.IOException
inputDocument
- The Document to be transformedxslFileNames
- A list of Strings naming the
xsl files to be applied sequentially.javax.xml.transform.TransformerException
- If there is a
a problem creating a new Transformer or parser.java.io.IOException
- If there is a problem closing the output
stream.public static void transform(java.lang.String input, java.io.FileWriter fileWriter, java.util.List xslFileNames) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerException, java.io.IOException
input
- The XML to be transformedfileWriter
- A FileWriter that will write to the MoML
file. The caller of this method is responsible for closing
the the FileWriter.xslFileNames
- A list of Strings naming the
xsl files to be applied sequentially.javax.xml.parsers.ParserConfigurationException
- If there is a problem
creating the DocumentBuilder.javax.xml.transform.TransformerException
- If there is a
a problem with the transform.java.io.IOException
- If there is a problem
finding a transform file or applying a transform.