# 4XSLT Processor

### The Processor

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.

Please see the 4XSLT command line documentation for command line help

## Module xml.xslt

Module Summary

- Classes

### Classes

Class Summary
`Processor` |
`XsltContext` | Represents the context used for XPattern processing at any given point

#### Class Processor

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__

`__init__(reader)`

> Create a new Processor instance

> Parameters
> `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.

> Return Value

> > None

#### registerExtensionModules

`registerExtensionModules(moduleList)`

> Adds a module containing extension functions/elements to the list of available extensions

> Parameters
> `moduleList` of type List of python module names

>   The module names to be searched for extension elements and functions

> Return Value

> > None

#### setStylesheetReader

`setStylesheetReader(styInst)`

> Set the instance of the StylesheetReader class used when a stylesheet is loaded.

> Parameters
> `styInst` of type A python instance that supports the interface of Ft.Xslt.StylesheetReader.StylesheetReader.

>   The instance used to read in stylesheets.

> Return Value

> > None

#### setDocumentReader

`setDocumentReader(docInst)`

> Set the instance of the Reader class used when a XML document is loaded.

> Parameters
> `docInst` of type Instance supporting the interface of xml.dom.ext.reader.Reader

>   The instance used to read in documents.

> Return Value

> > None

#### appendStylesheetStream

`appendStylesheetStream(stream)`

> Adds a new stylesheet from a file-like object to the processor

> Parameters
> `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.

> Return Value

> > None

> Throws
> xml.xslt.XsltException

> xml.sax.SAXParseException

> xml.sax.SAXException

#### appendStylesheetUri

`appendStylesheetUri(styleSheetUri)`

> Adds a new stylesheet from an URI to the processor

> Parameters
> `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.

> Return Value

> > None

> Throws
> xml.xslt.XsltException

> xml.sax.SAXParseException

> xml.sax.SAXException

#### appendStylesheetNode

`appendStylesheetNode(styleSheetNode, baseUri="")`

> Adds a new stylesheet to the proceesor from an existing DOM tree

> Parameters
> `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.

> Return Value

> > None

> Throws
> xml.xslt.XsltException

> xml.sax.SAXParseException

> xml.sax.SAXException

#### appendStylesheetString

`appendStylesheetString(styleSheetString, baseUri="")`

> Adds a new stylesheet from a string to the processor

> Parameters
> `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.

> Return Value

> > None

> Throws
> xml.xslt.XsltException

> xml.sax.SAXParseException

> xml.sax.SAXException

#### runStream

`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

> Parameters
> `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, the appropriate writer sets a default.

> Return Value
> python object

>   The return value is determined by the writer object used for output

> Throws
> xml.xslt.XsltException

> xml.sax.SAXParseException

> xml.sax.SAXException

#### runUri

`runUri(uri, ignorePis=0, topLevelParams=None, writer=None, outputStream=None)`

> Processes the document specified by the URI with the current stylesheets

> Parameters
> `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.

> Return Value
> python object

>   The return value is determined by the writer object used for output

> Throws
> xml.xslt.XsltException

> xml.sax.SAXParseException

> xml.sax.SAXException

#### runString

`runString(xmlString, ignorePis=0, topLevelParams=None, writer=None, baseUri="", outputStream=None)`

> Parses the document given in the string and processes with current stylesheets

> Parameters
> `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, the appropriate writer sets a default.

> Return Value
> python object

>   The return value is determined by the writer object used for output

> Throws
> xml.xslt.XsltException

> xml.sax.SAXParseException

> xml.sax.SAXException

#### runNode

`runNode(node, ignorePis=0, topLevelParams=None, writer=None, baseUri='', outputStream=None)`

> Processes the DOM tree with the current stylesheets

> Parameters
> `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, the appropriate writer sets a default.

> Return Value
> python object

>   The return value is determined by the writer object used for output

> Throws
> xml.xslt.XsltException

> xml.sax.SAXParseException

> xml.sax.SAXException

#### Class XsltContext

Represents the context used for XPattern processing at any given point

Base Classes

- xml.xpath.Context

Attribute 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__

`__init__(node, position, size, currentNode=None, varBindings=None, processorNss=None, stylesheet=None, mode=None)`

> Parameters
> `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.

> Return Value

> > None

#### reclaim

`reclaim()`

> Release all objects with circular references on the context, documents and RTFs. Not necessary in Python 2.x.

> Parameters

> > None

> Return Value

> > None