XSLTProcessor

Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

An XSLTProcessor applies an XSLT stylesheet transformation to an XML document to produce a new XML document as output. It has methods to load the XSLT stylesheet, to manipulate <xsl:param> parameter values, and to apply the transformation to documents.

Syntax

The constructor has no parameters.

new XSLTProcessor()

Methods

[Throws] void XSLTProcessor.importStylesheet(Node styleSheet)

Imports the XSLT stylesheet. If the given node is a document node, you can pass in a full XSL Transform or a literal result element transform; otherwise, it must be an <xsl:stylesheet> or <xsl:transform> element.

[Throws] DocumentFragment XSLTProcessor.transformToFragment(Node source, Document owner)

Transforms the node source by applying the stylesheet imported using the XSLTProcessor.importStylesheet() function. The owner document of the resulting document fragment is the owner node.

[Throws] Document XSLTProcessor.transformToDocument(Node source)

Transforms the node source applying the stylesheet given importing using the XSLTProcessor.importStylesheet() function.

The resultant object depends on the output method of the stylesheet:

Output method Result type
html HTMLDocument
xml XMLDocument
text XMLDocument with a single root element <transformiix:result> with the text as a child
[Throws] void XSLTProcessor.setParameter(String namespaceURI, String localName, any value)

Sets a parameter in the XSLT stylesheet that was imported. (Sets the value of an <xsl:param>.) A null value for namespaceURI is treated the same as an empty string.

[Throws] any XSLTProcessor.getParameter(String namespaceURI, String localName)

Gets the value of a parameter from the XSLT stylesheet. A null value for namespaceURI is treated the same as an empty string.

[Throws] void XSLTProcessor.removeParameter(String namespaceURI, String localName)

Removes the parameter if it was previously set. This will make the XSLTProcessor use the default value for the parameter as specified in the stylesheet. A null value for namespaceURI is treated the same as an empty string.

void XSLTProcessor.clearParameters()

Removes all set parameters from the XSLTProcessor. The XSLTProcessor will then use the defaults specified in the XSLT stylesheet.

void XSLTProcessor.reset()

Removes all parameters and stylesheets from the XSLTProcessor.

Properties

Non-Web-exposed properties

The following properties are [ChromeOnly] and not exposed to Web content:

[ChromeOnly] attribute unsigned long XSLTProcessor.flags

Flags that tweak the behavior of the processor. Not reset by calling XSLTProcessor.reset(). Default value: 0

Possible values are:

Name Value Effect
(None) 0 None
DISABLE_ALL_LOADS 1 Disable loading external documents (via e.g. <xsl:import> and document())

Examples

  1. Basic example
  2. Advanced example
  3. Additional example

Specifications

Not part of any specification. This is a proprietary interface that originated in Gecko.

Gecko IDL

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
XSLTProcessor
1
12
1
No
≤12.1
3.1
≤37
18
4
≤12.1
2
1.0
XSLTProcessor
1
12
1
No
≤12.1
≤4
≤37
18
4
≤12.1
≤3
1.0
clearParameters
1
12
1
No
≤12.1
3.1
≤37
18
4
≤12.1
2
1.0
getParameter
1
Chrome only supports string values.
12
Edge only supports string values.
1
No
≤12.1
Opera only supports string values.
3.1
Safari only supports string values.
≤37
WebView only supports string values.
18
Chrome only supports string values.
4
≤12.1
Opera only supports string values.
2
Safari only supports string values.
1.0
Samsung Internet only supports string values.
importStylesheet
1
12
1
No
≤12.1
3.1
≤37
18
4
≤12.1
2
1.0
removeParameter
1
12
1
No
≤12.1
3.1
≤37
18
4
≤12.1
2
1.0
reset
1
12
1
No
≤12.1
3.1
≤37
18
4
≤12.1
2
1.0
setParameter
1
Chrome only supports string values.
12
Edge only supports string values.
1
No
≤12.1
Opera only supports string values.
3.1
Safari only supports string values.
≤37
WebView only supports string values.
18
Chrome only supports string values.
4
≤12.1
Opera only supports string values.
2
Safari only supports string values.
1.0
Samsung Internet only supports string values.
transformToDocument
1
Chrome returns null if an error occurs.
12
Edge returns null if an error occurs.
1
Firefox throws an exception if an error occurs.
No
≤12.1
["Opera 12.1 and earlier throws an exception if an error occurs.", "Opera 15 and later returns null if an error occurs."]
3.1
Safari returns null if an error occurs.
≤37
WebView returns null if an error occurs.
18
Chrome returns null if an error occurs.
4
Firefox throws an exception if an error occurs.
≤12.1
["Opera Android 12.1 and earlier throws an exception if an error occurs.", "Opera Android 14 and later returns null if an error occurs."]
2
Safari returns null if an error occurs.
1.0
Samsung Internet returns null if an error occurs.
transformToFragment
1
Chrome returns null if an error occurs.
12
Edge returns null if an error occurs.
1
Firefox throws an exception if an error occurs.
No
≤12.1
["Opera 12.1 and earlier throws an exception if an error occurs.", "Opera 15 and later returns null if an error occurs."]
3.1
Safari returns null if an error occurs.
≤37
WebView returns null if an error occurs.
18
Chrome returns null if an error occurs.
4
Firefox throws an exception if an error occurs.
≤12.1
["Opera Android 12.1 and earlier throws an exception if an error occurs.", "Opera Android 14 and later returns null if an error occurs."]
2
Safari returns null if an error occurs.
1.0
Samsung Internet returns null if an error occurs.

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XSLTProcessor