XSLTProcessor

非标
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.

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

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.

句法

The constructor has no parameters.

new XSLTProcessor()
					

方法

[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> 元素。
[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() 函数。

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 XSLTProcessor will then use the defaults specified in the XSLT stylesheet.
void XSLTProcessor.reset()
Removes all parameters and stylesheets from the XSLTProcessor .

特性

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 Effect
(None) 0 None
DISABLE_ALL_LOADS 1 Disable loading external documents (via e.g. <xsl:import> and document() )

范例

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

规范

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

Gecko IDL

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
XSLTProcessor
非标
Chrome Yes Edge ≤18 Firefox Yes IE No Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
clearParameters
非标
Chrome Yes Edge 12 Firefox Yes IE No Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
getParameter
非标
Chrome Yes
Yes
Chrome only supports string values.
Edge 12 Firefox Yes IE No Opera Yes
Yes
Opera only supports string values.
Safari Yes WebView Android Yes
Yes
Chrome only supports string values.
Chrome Android Yes
Yes
Chrome only supports string values.
Firefox Android Yes Opera Android Yes
Yes
Opera only supports string values.
Safari iOS Yes Samsung Internet Android Yes
Yes
Samsung Internet only supports string values.
importStylesheet
非标
Chrome Yes Edge 12 Firefox Yes IE No Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
removeParameter
非标
Chrome Yes Edge 12 Firefox Yes IE No Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
reset
非标
Chrome Yes Edge 12 Firefox Yes IE No Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
setParameter
非标
Chrome Yes
Yes
Chrome only supports string values.
Edge 12 Firefox Yes IE No Opera Yes
Yes
Opera only supports string values.
Safari Yes WebView Android Yes
Yes
Chrome only supports string values.
Chrome Android Yes
Yes
Chrome only supports string values.
Firefox Android Yes Opera Android Yes
Yes
Opera only supports string values.
Safari iOS Yes Samsung Internet Android Yes
Yes
Samsung Internet only supports string values.
transformToDocument
非标
Chrome Yes
Yes
Chrome returns null if an error occurs.
Edge 12 Firefox Yes
Yes
Firefox throws an exception if an error occurs.
IE No Opera Yes
Yes
Opera returns null if an error occurs.
Safari Yes WebView Android Yes
Yes
Chrome returns null if an error occurs.
Chrome Android Yes
Yes
Chrome returns null if an error occurs.
Firefox Android Yes
Yes
Firefox throws an exception if an error occurs.
Opera Android Yes
Yes
Opera returns null if an error occurs.
Safari iOS Yes Samsung Internet Android Yes
Yes
Samsung Internet returns null if an error occurs.
transformToFragment
非标
Chrome Yes
Yes
Chrome returns null if an error occurs.
Edge 12 Firefox Yes
Yes
Firefox throws an exception if an error occurs.
IE No Opera Yes
Yes
Opera returns null if an error occurs.
Safari Yes WebView Android Yes
Yes
Chrome returns null if an error occurs.
Chrome Android Yes
Yes
Chrome returns null if an error occurs.
Firefox Android Yes
Yes
Firefox throws an exception if an error occurs.
Opera Android Yes
Yes
Opera returns null if an error occurs.
Safari iOS Yes Samsung Internet Android Yes
Yes
Samsung Internet returns null if an error occurs.

图例

完整支持
完整支持
不支持
不支持
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
非标。预期跨浏览器支持较差。
非标。预期跨浏览器支持较差。
见实现注意事项。

另请参阅

  1. XSLTProcessor