aboutsummaryrefslogtreecommitdiff
path: root/files/ar/web/api/xsltprocessor/index.html
blob: dbc44795dae7b784d57c59d67fe8d7a482543cab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
title: XSLTProcessor
slug: Web/API/XSLTProcessor
tags:
  - API
  - DOM
  - DOM Reference
  - NeedsTranslation
  - Reference
  - TopicStub
  - XSLT
translation_of: Web/API/XSLTProcessor
---
<div>{{Non-standard_header}}{{SeeCompatTable}}{{APIRef("XSLT")}}</div>

<p>An <strong><code>XSLTProcessor</code></strong> applies an <a href="/en-US/docs/Web/XSLT">XSLT</a> stylesheet transformation to an XML document to produce a new XML document as output. It has methods to load the XSLT stylesheet, to manipulate <code>&lt;xsl:param&gt;</code> parameter values, and to apply the transformation to documents.</p>

<h2 id="Syntax">Syntax</h2>

<p>The constructor has no parameters.</p>

<pre class="syntaxbox">new XSLTProcessor()</pre>

<h2 id="Methods">Methods</h2>

<dl>
 <dt><code><a href="/en-US/docs/Mozilla/WebIDL_bindings#Throws">[Throws]</a> void </code>{{domxref("XSLTProcessor.importStylesheet")}}<code>(</code>{{domxref("Node")}}<code> styleSheet)</code></dt>
 <dd>Imports the XSLT stylesheet. If the given node is a document node, you can pass in a full XSL Transform or a <a class="external" href="http://www.w3.org/TR/xslt#result-element-stylesheet">literal result element transform</a>; otherwise, it must be an <code>&lt;xsl:stylesheet&gt;</code> or <code>&lt;xsl:transform&gt;</code> element.</dd>
 <dt><code><a href="/en-US/docs/Mozilla/WebIDL_bindings#Throws">[Throws]</a> </code>{{domxref("DocumentFragment")}} {{domxref("XSLTProcessor.transformToFragment")}}<code>(</code>{{domxref("Node")}}<code> source, </code>{{domxref("Document")}}<code> owner)</code></dt>
 <dd>Transforms the node source by applying the stylesheet imported using the {{domxref("XSLTProcessor.importStylesheet()")}} function. The owner document of the resulting document fragment is the owner node.</dd>
 <dt><code><a href="/en-US/docs/Mozilla/WebIDL_bindings#Throws">[Throws]</a></code> {{domxref("Document")}} {{domxref("XSLTProcessor.transformToDocument")}}<code>(</code>{{domxref("Node")}}<code> source)</code></dt>
 <dd>
 <p>Transforms the node source applying the stylesheet given importing using the {{domxref("XSLTProcessor.importStylesheet()")}} function.</p>

 <p>The resultant object depends on the <a class="external" href="http://www.w3.org/TR/xslt#output">output method</a> of the stylesheet:</p>

 <table class="standard-table">
  <thead>
   <tr>
    <th scope="col">Output method</th>
    <th scope="col">Result type</th>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td><code>html</code></td>
    <td>{{domxref("HTMLDocument")}}</td>
   </tr>
   <tr>
    <td><code>xml</code></td>
    <td>{{domxref("XMLDocument")}}</td>
   </tr>
   <tr>
    <td><code>text</code></td>
    <td>{{domxref("XMLDocument")}} with a single root element <code>&lt;transformiix:result&gt;</code> with the text as a child</td>
   </tr>
  </tbody>
 </table>
 </dd>
 <dt><code><a href="/en-US/docs/Mozilla/WebIDL_bindings#Throws">[Throws]</a> void </code>{{domxref("XSLTProcessor.setParameter")}}<code>(</code>{{jsxref("String")}}<code> namespaceURI, </code>{{jsxref("String")}}<code> localName, any value)</code></dt>
 <dd>Sets a parameter in the XSLT stylesheet that was imported. (Sets the value of an <code>&lt;xsl:param&gt;</code>.) A null value for <code>namespaceURI</code> is treated the same as an empty string.</dd>
 <dt><code><a href="/en-US/docs/Mozilla/WebIDL_bindings#Throws">[Throws]</a> any </code>{{domxref("XSLTProcessor.getParameter")}}<code>(</code>{{jsxref("String")}}<code> namespaceURI, </code>{{jsxref("String")}}<code> localName)</code></dt>
 <dd>Gets the value of a parameter from the XSLT stylesheet. A null value for <code>namespaceURI</code> is treated the same as an empty string.</dd>
 <dt><code><a href="/en-US/docs/Mozilla/WebIDL_bindings#Throws">[Throws]</a> void </code>{{domxref("XSLTProcessor.removeParameter")}}<code>(</code>{{jsxref("String")}}<code> namespaceURI, </code>{{jsxref("String")}}<code> localName)</code></dt>
 <dd>Removes the parameter if it was previously set. This will make the <code>XSLTProcessor</code> use the default value for the parameter as specified in the stylesheet. A null value for <code>namespaceURI</code> is treated the same as an empty string.</dd>
 <dt><code>void </code>{{domxref("XSLTProcessor.clearParameters()")}}</dt>
 <dd>Removes all set parameters from the <code>XSLTProcessor</code>. The <code>XSLTProcessor</code> will then use the defaults specified in the XSLT stylesheet.</dd>
 <dt><code>void </code>{{domxref("XSLTProcessor.reset()")}}</dt>
 <dd>Removes all parameters and stylesheets from the <code>XSLTProcessor</code>.</dd>
</dl>

<h2 id="Properties">Properties</h2>

<h3 id="Non-Web-exposed_properties">Non-Web-exposed properties</h3>

<p>The following properties are <a href="/en-US/docs/Mozilla/WebIDL_bindings#ChromeOnly"><code>[ChromeOnly]</code></a> and not exposed to Web content:</p>

<dl>
 <dt><code><a href="/en-US/docs/Mozilla/WebIDL_bindings#ChromeOnly">[ChromeOnly]</a> attribute unsigned long </code>{{domxref("XSLTProcessor.flags")}}</dt>
 <dd>
 <p>Flags that tweak the behavior of the processor. Not reset by calling {{domxref("XSLTProcessor.reset()")}}. Default value: <code>0</code></p>

 <p>Possible values are:</p>

 <table class="standard-table">
  <thead>
   <tr>
    <th scope="col">Name</th>
    <th scope="col">Value</th>
    <th scope="col">Effect</th>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td>(None)</td>
    <td><code>0</code></td>
    <td>None</td>
   </tr>
   <tr>
    <td><code>DISABLE_ALL_LOADS</code></td>
    <td><code>1</code></td>
    <td>Disable loading external documents (via e.g. <code>&lt;xsl:import&gt;</code> and <code>document()</code>)</td>
   </tr>
  </tbody>
 </table>
 </dd>
</dl>

<h2 id="Examples">Examples</h2>

<ol>
 <li><a href="/en-US/docs/XSLT/XSLT_JS_Interface_in_Gecko/Basic_Example">Basic example</a></li>
 <li><a href="/en-US/docs/XSLT/XSLT_JS_Interface_in_Gecko/Advanced_Example">Advanced example</a></li>
 <li><a href="/en-US/docs/XSLT/XSLT_JS_Interface_in_Gecko/JavaScript_XSLT_Bindings">Additional example</a></li>
</ol>

<h2 id="Specifications">Specifications</h2>

<p><em>Not part of any specification.</em> This is a proprietary interface that originated in Gecko.</p>

<h2 id="Gecko_IDL">Gecko IDL</h2>

<ul>
 <li><code>{{ Source("dom/webidl/XSLTProcessor.webidl", "XSLTProcessor.webidl") }}</code></li>
 <li><code>{{ Source("dom/xslt/nsIXSLTProcessor.idl", "nsIXSLTProcessor.idl") }}</code></li>
</ul>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.XSLTProcessor")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations">Using the Mozilla JavaScript interface to XSL Transformations</a></li>
</ul>