XsltProcessor Class
Transforms nodes with an XSLT 1.0 stylesheet (https://dom.spec.whatwg.org/#interface-xsltprocessor, https://www.w3.org/TR/xslt-10/), as the browsers do.
public sealed class XsltProcessorRemarks
The stylesheet is compiled when the first transformation runs, and its xsl:include and xsl:import elements load their stylesheets synchronously with the fetch of the document of the current global object (the same-origin requests of destination xslt, checked by its content security policies). As in Chromium, the document() function returns an empty node-set, and the disable-output-escaping attributes are ignored.
The XPath expressions are evaluated by System.Xml.XPath over the DOM: the stylesheet is interpreted, so the transformations work without dynamic code (with native AOT). A recursion deeper than 3000 templates is an error.
The transformations are bounded by the BrowsingContextOptions.Xslt options of the browsing context of the relevant document (XsltOptions.Default without browsing context): a transformation that exceeds them is an error. A transformation run by a script also stops when the script engine interrupts the script (e.g. its timeout).
See also
Constructors
| Name | Description |
|---|---|
| XsltProcessor() | Creates a processor associated with the current global document. |
XsltProcessor()
XsltProcessor.csCreates a processor associated with the current global document.
public XsltProcessor()Methods
| Name | Description |
|---|---|
| ClearParameters() | Removes all the parameters. |
| GetParameter(string, string) | Returns the value of a parameter set by XsltProcessor.SetParameter, or null. |
| ImportStylesheet(Node) | Imports a stylesheet: a document whose document element is an xsl:stylesheet or xsl:transform element (or a literal result element with an xsl:version attribute), or such an element. The stylesheet replaces the previous one; it is compiled by the next transformation. |
| RemoveParameter(string, string) | Removes a parameter set by XsltProcessor.SetParameter. |
| Reset() | Removes the stylesheet and all the parameters. |
| SetParameter(string, string, object?) | Sets the value of a global parameter of the stylesheet (an xsl:param element). A string, a number and a boolean are the XPath values; a node, or a list of nodes, is a node-set; any other value is converted to a string. |
| TransformToDocument(Node) | Transforms a node, and returns the result tree as a new document that has no browsing context: an HTML document for the html output method, an XML document for the xml output method, and an HTML document whose text is in a pre element for the text output method. Its scripts never run. |
| TransformToFragment(Node, Document) | Transforms a node, and returns the nodes of the result tree in a fragment owned by output. With the html output method, or without output method when output is an HTML document, the elements in no namespace are HTML elements. The scripts of the fragment run when it is inserted in a document. |
ClearParameters()
XsltProcessor.csRemoves all the parameters.
public void ClearParameters()GetParameter(string, string)
XsltProcessor.csReturns the value of a parameter set by XsltProcessor.SetParameter, or null.
Parameters
Returns
See also
ImportStylesheet(Node)
XsltProcessor.csImports a stylesheet: a document whose document element is an xsl:stylesheet or xsl:transform element (or a literal result element with an xsl:version attribute), or such an element. The stylesheet replaces the previous one; it is compiled by the next transformation.
Parameters
styleNode
Exceptions
DomException- The node is not a document or an element (
NotSupportedError).
See also
RemoveParameter(string, string)
XsltProcessor.csRemoves a parameter set by XsltProcessor.SetParameter.
Parameters
See also
Reset()
XsltProcessor.csRemoves the stylesheet and all the parameters.
public void Reset()SetParameter(string, string, object?)
XsltProcessor.csSets the value of a global parameter of the stylesheet (an xsl:param element). A string, a number and a boolean are the XPath values; a node, or a list of nodes, is a node-set; any other value is converted to a string.
Parameters
See also
TransformToDocument(Node)
XsltProcessor.csTransforms a node, and returns the result tree as a new document that has no browsing context: an HTML document for the html output method, an XML document for the xml output method, and an HTML document whose text is in a pre element for the text output method. Its scripts never run.
Parameters
sourceNode
Returns
Exceptions
DomException- No stylesheet is imported (
InvalidStateError), the source is not a node that XPath represents (NotSupportedError), or the stylesheet is not valid or the transformation fails (OperationError).
See also
TransformToFragment(Node, Document)
XsltProcessor.csTransforms a node, and returns the nodes of the result tree in a fragment owned by output. With the html output method, or without output method when output is an HTML document, the elements in no namespace are HTML elements. The scripts of the fragment run when it is inserted in a document.
public DocumentFragment TransformToFragment(Node source, Document output)Parameters
Returns
Exceptions
DomException- No stylesheet is imported (
InvalidStateError), the source is not a node that XPath represents (NotSupportedError), or the stylesheet is not valid or the transformation fails (OperationError).