Feedback

  • Contents
 

XML Transform To Document

This XML tool processes the given node and its children by applying an XSLT style-sheet. The transformation result is returned as XML document node. The Source node defines a context for the style-sheet to operate on, but navigation outside this scope is allowed. For instance, a style-sheet could use the ancestor or id methods to access other parts of the source document.

This tool allows passing parameters to the style-sheet. Two kind of parameters are supported:

  • String parameters are defined as two lists whereas one contains the parameter names and the other the corresponding values. A namespace URI identifies the parameters in the style sheet. For the use of the String Parameters, consult the example below.

  • Node Parameters are a list of XML nodes. These nodes are accessible through the DOM interface in the style-sheet. Each node is identified by a namespace URI supplied in a list of strings (‘Node Parameter Namespace URIs’), where each item specifies the namespace URI of the node in the same position in ‘Node Parameter List’.

To increase flexibility even further, the start mode of the style-sheet can be specified through the ‘Start Mode’ argument. Specifying the start mode can be useful to render different kinds of result documents based on some external condition, such as a debug mode.

The stylesheet does not have to be a document node, it may be any element node, as long as it is the root of a valid (X)SLT stylesheet. This allows, for example, to use documents with embedded stylesheets and use a selection step to pick a stylesheet to use.

Note 1: If the stylesheet node is not a document node or root element of a document, the stylesheet template will never be cached in a pre-compiled form (see XML Create Document or XML Load Document). It is therefore recommended to define frequently used stylesheets as separate documents to benefit from the performance improvement of cached, pre-compiled stylesheet templates.

Note 2: Even if an error occurs during the transformation, a document is returned in ‘Document’. This document will most likely be empty, but can be passed to XML Get Error Info to retrieve verbose information about what went wrong. In most cases this error will be a style sheet error or a parse error of the resulting document (i.e. the resulting document is not well formed).

Note 3: The resulting document must obviously be well-formed XML in order to be returned as document. Care must be taken when HTML output is produced (<xsl:output method="html"/>), as some HTML tags do not constitute well formed XML (such as the META tag). If HTML output is to be produced, we recommend using the XML Transform To String tool instead.

Example: Source document:

<items>
<item id="1">This is Item 1</item>
<item id="2">This is Item 2</item>
<item id="3">This is Item 3</item>
<item id="4">This is Item 4</item>
</items>

Style-sheet:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:params="urn:my-params"
exclude-result-prefixes="params"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="params:itemID"/>
<xsl:template match="/">
<result>
<xsl:text>Value: </xsl:text>
<xsl:value-of select="/items/item[@id=$params:itemID]"/>
</result>
</xsl:template>
</xsl:stylesheet>

String Parameter:

String Parameter Names:  "itemID"
String Parameter Values:  "2"
String Parameter Namespace URI:  "urn:my-params"

Result:

<?xml version="1.0"?>
<result>Value: This is Item 2</result>

Inputs

Source

Node defining the context from which to start the transformation.

Stylesheet

Stylesheet to apply. This may be a document or an Element node representing a style sheet fragment.

String Parameter Names

Optional. List of names of the parameters passed to the XSLT style-sheet. Each item is paired up with the corresponding item in 'String Parameter Values’.

String Parameter Values

Optional. List of string values passed as parameters to the XSLT style-sheet. Each item is paired with the corresponding item in ‘String Parameter Names’.

String Parameter Namespace URI

Optional. Namespace URI of the parameters passed to the XSLT style-sheet.

Node Parameter List

Optional. List of nodes to pass as parameters to the XSLT style-sheet. The nodes in the list are paired with the corresponding item in the ‘Node Parameter Namespace URIs’ argument.

Node Parameter Namespace URLs

Optional. List of namespaces that identify the corresponding object from the ‘Node Parameter List’ argument in the style-sheet.

Start Mode

Optional. Start mode for the XSLT transformation. This allows to specify a subset out of a larger XSLT style-sheet.

Start Mode Namespace URI

Optional. Namespace URI for the start mode. Allows to fully qualify the mode name.

Outputs

Result Document

Document node of the transformation result. A document node (usually empty) will be returned even if an error occurs during the transformation (unless the error is catastrophic). Pass to XML Get Error Info to retrieve verbose information.

Result Document Element

Root node (Element) of the document created as result of the transformation. NULL if error.

Exit Paths

Success

This path is taken if the document has been successfully transformed.

Failure

This path is taken if the operation fails.