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.

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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
ExperimentalNon-standard
Chrome Full support YesEdge Full support YesFirefox Full support YesIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
importStylesheet
ExperimentalNon-standard
Chrome Full support YesEdge Full support YesFirefox Full support YesIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
transformToFragment
ExperimentalNon-standard
Chrome Full support Yes
Notes
Full support Yes
Notes
Notes Chrome returns nullif an error occurs.
Edge Full support YesFirefox Full support Yes
Notes
Full support Yes
Notes
Notes Firefox throws an exception if an error occurs.
IE No support NoOpera Full support Yes
Notes
Full support Yes
Notes
Notes Opera returns nullif an error occurs.
Safari Full support YesWebView Android Full support Yes
Notes
Full support Yes
Notes
Notes Chrome returns nullif an error occurs.
Chrome Android Full support Yes
Notes
Full support Yes
Notes
Notes Chrome returns nullif an error occurs.
Edge Mobile Full support YesFirefox Android Full support Yes
Notes
Full support Yes
Notes
Notes Firefox throws an exception if an error occurs.
Opera Android Full support Yes
Notes
Full support Yes
Notes
Notes Opera returns nullif an error occurs.
Safari iOS Full support YesSamsung Internet Android Full support Yes
transformToDocument
ExperimentalNon-standard
Chrome Full support Yes
Notes
Full support Yes
Notes
Notes Chrome returns nullif an error occurs.
Edge Full support YesFirefox Full support Yes
Notes
Full support Yes
Notes
Notes Firefox throws an exception if an error occurs.
IE No support NoOpera Full support Yes
Notes
Full support Yes
Notes
Notes Opera returns nullif an error occurs.
Safari Full support YesWebView Android Full support Yes
Notes
Full support Yes
Notes
Notes Chrome returns nullif an error occurs.
Chrome Android Full support Yes
Notes
Full support Yes
Notes
Notes Chrome returns nullif an error occurs.
Edge Mobile Full support YesFirefox Android Full support Yes
Notes
Full support Yes
Notes
Notes Firefox throws an exception if an error occurs.
Opera Android Full support Yes
Notes
Full support Yes
Notes
Notes Opera returns nullif an error occurs.
Safari iOS Full support YesSamsung Internet Android Full support Yes
setParameter
ExperimentalNon-standard
Chrome Full support Yes
Notes
Full support Yes
Notes
Notes Chrome only supports string values.
Edge Full support YesFirefox Full support YesIE No support NoOpera Full support Yes
Notes
Full support Yes
Notes
Notes Opera only supports string values.
Safari Full support YesWebView Android Full support Yes
Notes
Full support Yes
Notes
Notes Chrome only supports string values.
Chrome Android Full support Yes
Notes
Full support Yes
Notes
Notes Chrome only supports string values.
Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support Yes
Notes
Full support Yes
Notes
Notes Opera only supports string values.
Safari iOS Full support YesSamsung Internet Android Full support Yes
getParameter
ExperimentalNon-standard
Chrome Full support Yes
Notes
Full support Yes
Notes
Notes Chrome only supports string values.
Edge Full support YesFirefox Full support YesIE No support NoOpera Full support Yes
Notes
Full support Yes
Notes
Notes Opera only supports string values.
Safari Full support YesWebView Android Full support Yes
Notes
Full support Yes
Notes
Notes Chrome only supports string values.
Chrome Android Full support Yes
Notes
Full support Yes
Notes
Notes Chrome only supports string values.
Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support Yes
Notes
Full support Yes
Notes
Notes Opera only supports string values.
Safari iOS Full support YesSamsung Internet Android Full support Yes
removeParameter
ExperimentalNon-standard
Chrome Full support YesEdge Full support YesFirefox Full support YesIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
clearParameters
ExperimentalNon-standard
Chrome Full support YesEdge Full support YesFirefox Full support YesIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
reset
ExperimentalNon-standard
Chrome Full support YesEdge Full support YesFirefox Full support YesIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
See implementation notes.
See implementation notes.

See also

Document Tags and Contributors

Contributors to this page: ExE-Boss, fscholz, erikadoyle, rolfedh, cvrebert
Last updated by: ExE-Boss,