4XSLT can be used from the command line as described in the README, but if you want to embed or extend 4XSLT, you will typically use the Processor class directly.
Module Summary
Process an XML file against stylesheets from the command line
4xslt [-i] [-v] [-o = <output_filename>] [-D = <var_name>=<value>] source_uri [stylesheet...]
Argument Summary | |
-i
|
Ignore Processing Instructions |
-v
|
Validate the source document |
-o
|
Specify a filename for the output. This file will be overwritten if present. |
-D
|
Bind a top-level parameter, overriding any binding in the stylesheet |
source_uri
|
URI of the source document (required) |
stylesheet
|
URI the stylesheets |
Class Summary | |
Processor
|
|
XsltContext
|
Represents the context used for XPattern processing at any given point |
Method Summary | |
__init__
|
Create a new Processor instance |
registerExtensionModules
|
Adds a module containing extension functions/elements to the list of available extensions |
setStylesheetReader
|
Set the instance of the StylesheetReader class used when a stylesheet is loaded. |
setDocumentReader
|
Set the instance of the Reader class used when a XML document is loaded. |
appendStylesheetStream
|
Adds a new stylesheet from a file-like object to the processor |
appendStylesheetUri
|
Adds a new stylesheet from an URI to the processor |
appendStylesheetNode
|
Adds a new stylesheet to the proceesor from an existing DOM tree |
appendStylesheetString
|
Adds a new stylesheet from a string to the processor |
runStream
|
Parses the document read from a file-like object and processes with current stylesheets |
runUri
|
Processes the document specified by the URI with the current stylesheets |
runString
|
Parses the document given in the string and processes with current stylesheets |
runNode
|
Processes the DOM tree with the current stylesheets |
Method Details |
__init__(reader)
Create a new Processor instance
ParametersReturn Value
reader
of type Instance supporting the interface of xml.dom.ext.reader.Reader
The reader class that will be used by the processor to generate source document DOM from serialized XML.
None
registerExtensionModules(moduleList)
Adds a module containing extension functions/elements to the list of available extensions
ParametersReturn Value
moduleList
of type List of python module names
The module names to be searched for extension elements and functions
None
setStylesheetReader(styInst)
Set the instance of the StylesheetReader class used when a stylesheet is loaded.
ParametersReturn Value
styInst
of type A python instance that supports the interface of Ft.Xslt.StylesheetReader.StylesheetReader.
The instance used to read in stylesheets.
None
setDocumentReader(docInst)
Set the instance of the Reader class used when a XML document is loaded.
ParametersReturn Value
docInst
of type Instance supporting the interface of xml.dom.ext.reader.Reader
The instance used to read in documents.
None
appendStylesheetStream(stream)
Adds a new stylesheet from a file-like object to the processor
ParametersReturn Value
stream
of type file-like object
Read an XSLT stylesheet from the stream and append it to the list of stylesheets used by the processor.
NoneThrows
- xml.xslt.XsltException
- xml.sax.SAXParseException
- xml.sax.SAXException
appendStylesheetUri(styleSheetUri)
Adds a new stylesheet from an URI to the processor
ParametersReturn Value
styleSheetUri
of type string
Retrieve text from the URL as an XSLT stylesheet and append it to the list of stylesheets used by the processor.
NoneThrows
- xml.xslt.XsltException
- xml.sax.SAXParseException
- xml.sax.SAXException
appendStylesheetNode(styleSheetNode, baseUri="")
Adds a new stylesheet to the proceesor from an existing DOM tree
ParametersReturn Value
styleSheetNode
of type xml.dom.Node
Process the DOM node as a stylesheet and append to the list of stylesheets used by the processor.
baseUri
of type string
The baseUri used to resolve relative URI's in the stylesheet.
NoneThrows
- xml.xslt.XsltException
- xml.sax.SAXParseException
- xml.sax.SAXException
appendStylesheetString(styleSheetString, baseUri="")
Adds a new stylesheet from a string to the processor
ParametersReturn Value
styleSheetString
of type string
Parse the string as an XSLT stylesheet and append it to the list of stylesheets used by the processor.
baseUri
of type string
The baseUri used to resolve relative URI's in the stylesheet.
NoneThrows
- xml.xslt.XsltException
- xml.sax.SAXParseException
- xml.sax.SAXException
runStream(stream, ignorePis=0, topLevelParams=None, writer=None, baseUri="", outputStream=None)
Parses the document read from a file-like object and processes with current stylesheets
ParametersReturn Value
stream
of type string
Text to run through the registered stylesheets.
ignorePis
of type integer
If 0, append any stylesheet processing instructions (PIs) embedded int he XML to the processor's stylesheets, otherwise ignore such PIs.
topLevelParams
of type dictionary
Maps tuples in the form (namespace-uri, local-name) representing top-level parameters defined in one of the registered stylesheet to an overriding value.
writer
of type Class that follows the protocol of xml.xslt.TextWriter.TextWriter, which is the default if None is given.
The output handler to be used
baseUri
of type string
The base URI of the given XML source (default is '')
outputStream
of type Python FileObject interface
The stream to send output too. If None, sys.stdout is used.
NoneThrows
- xml.xslt.XsltException
- xml.sax.SAXParseException
- xml.sax.SAXException
runUri(uri, ignorePis=0, topLevelParams=None, writer=None, outputStream=None)
Processes the document specified by the URI with the current stylesheets
ParametersReturn Value
uri
of type string
Retrieve text from the URI, and run it through the registered stylesheets.
ignorePis
of type integer
If 0, append any stylesheet processing instructions (PIs) embedded int he XML to the processor's stylesheets, otherwise ignore such PIs.
topLevelParams
of type dictionary
Maps tuples in the form (namespace-uri, local-name) representing top-level parameters defined in one of the registered stylesheet to an overriding value.
writer
of type Class that follows the protocol of xml.xslt.TextWriter.TextWriter, which is the default
The output handler to be used
outputStream
of type Python FileObject interface
The stream to send output too. If None, sys.stdout is used.
NoneThrows
- xml.xslt.XsltException
- xml.sax.SAXParseException
- xml.sax.SAXException
runString(xmlString, ignorePis=0, topLevelParams=None, writer=None, baseUri="", outputStream=None)
Parses the document given in the string and processes with current stylesheets
ParametersReturn Value
xmlString
of type string
Text to run through the registered stylesheets.
ignorePis
of type integer
If 0, append any stylesheet processing instructions (PIs) embedded int he XML to the processor's stylesheets, otherwise ignore such PIs.
topLevelParams
of type dictionary
Maps tuples in the form (namespace-uri, local-name) representing top-level parameters defined in one of the registered stylesheet to an overriding value.
writer
of type Class that follows the protocol of xml.xslt.TextWriter.TextWriter, which is the default if None is given.
The output handler to be used
baseUri
of type string
The base URI of the given XML source (default is '')
outputStream
of type Python FileObject interface
The stream to send output too. If None, sys.stdout is used.
NoneThrows
- xml.xslt.XsltException
- xml.sax.SAXParseException
- xml.sax.SAXException
runNode(node, ignorePis=0, topLevelParams=None, writer=None, baseUri='', outputStream=None)
Processes the DOM tree with the current stylesheets
ParametersReturn Value
node
of type xml.dom.Node
XML source DOM node to be run through the registered stylesheets.
ignorePis
of type integer
If 0, append any stylesheet processing instructions (PIs) embedded int he XML to the processor's stylesheets, otherwise ignore such PIs. (default is 0)
topLevelParams
of type dictionary
Maps tuples in the form (namespace-uri, local-name) representing top-level parameters defined in one of the registered stylesheet to an overriding value. (Defaults to the empty dictionary)
writer
of type Class that follows the protocol of xml.xslt.TextWriter.TextWriter, which is the default
The output handler to be used
baseUri
of type string
The base URI of the given XML source (default is '')
outputStream
of type Python FileObject interface
The stream to send output too. If None, sys.stdout is used.
NoneThrows
- xml.xslt.XsltException
- xml.sax.SAXParseException
- xml.sax.SAXException
Represents the context used for XPattern processing at any given point
Base ClassesAttribute Summary | |
currentNode
|
The current node in the XPattern expression. This node is returned as the result of the "current()" function. This is the node that was the context node at the beginning of the XPattern evaluation. |
stylesheet
|
The stylesheet that the current template matched. |
mode
|
The mode that the current template matched with. |
documents
|
Maps URIs to documents (for the document function) |
rtfs
|
A list of all of the result tree fragements made. These are stored so ReleaseNode can be called on them when processing is done. |
Method Summary | |
__init__
|
|
reclaim
|
Release all objects with circular references on the context, documents and RTFs. Not necessary in Python 2.x. |
Method Details |
__init__(node, position, size, currentNode=None, varBindings=None, processorNss=None, stylesheet=None, mode=None)
ParametersReturn Value
node
of type Python DOM binding node object
The context node, as used for computing XPath expressions
position
of type positive integer
The context node's position in the context node list, as returned by the XPath position() function
size
of type positive integer
The size of the context node list
currentNode
of type Python DOM binding node object
The current node in the XPattern expression. This node is returned as the result of the "current()" function. This is the node that was the context node at the beginning of the XPattern evaluation.
varBindings
of type dictionary with keys a tuple of two strings and value a string, integer, BooleanType or node set (list of nodes)
Maps variable and parameters by expanded name to the value of the variable. Defaults to an empty dictionary.
processorNss
of type dictionary with string key and value
provides expansion from namespace prefixes to uris for expanded names in name tests, variable names, etc. Defaults to an empty dictionary.
stylesheet
of type xml.xslt.Stylesheet.StylesheetElement
The stylesheet that the current template matched.
mode
of type string
The mode that the current template matched with.
None
reclaim()
Release all objects with circular references on the context, documents and RTFs. Not necessary in Python 2.x.
ParametersNoneReturn ValueNone