1
|
/**
|
2
|
* ====================================================================
|
3
|
* About
|
4
|
* ====================================================================
|
5
|
* Sarissa cross browser XML library - IE XSLT Emulation (deprecated)
|
6
|
* @version 0.9.7.6
|
7
|
* @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net
|
8
|
*
|
9
|
* This script emulates Internet Explorer's transformNode and transformNodeToObject
|
10
|
* for Mozilla and provides a common way to set XSLT parameters
|
11
|
* via Sarissa.setXslParameter.
|
12
|
*
|
13
|
* All functionality in this file is DEPRECATED, the XSLTProcessor
|
14
|
* should be used instead.
|
15
|
*
|
16
|
* ====================================================================
|
17
|
* Licence
|
18
|
* ====================================================================
|
19
|
* Sarissa is free software distributed under the GNU GPL version 2 (see <a href="gpl.txt">gpl.txt</a>) or higher,
|
20
|
* GNU LGPL version 2.1 (see <a href="lgpl.txt">lgpl.txt</a>) or higher and Apache Software License 2.0 or higher
|
21
|
* (see <a href="asl.txt">asl.txt</a>). This means you can choose one of the three and use that if you like. If
|
22
|
* you make modifications under the ASL, i would appreciate it if you submitted those.
|
23
|
* In case your copy of Sarissa does not include the license texts, you may find
|
24
|
* them online in various formats at <a href="http://www.gnu.org">http://www.gnu.org</a> and
|
25
|
* <a href="http://www.apache.org">http://www.apache.org</a>.
|
26
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
27
|
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
28
|
* WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE
|
29
|
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
30
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
31
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
32
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
33
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
34
|
*/
|
35
|
if(!Sarissa.IS_ENABLED_TRANSFORM_NODE && window.XSLTProcessor){
|
36
|
/**
|
37
|
* <p><b>Deprecated, will be removed in 0.9.6 (use XSLTProcessor instead): </b>Extends the Element class to emulate IE's transformNodeToObject (deprecated).
|
38
|
* <b>Note </b>: The transformation result <i>must </i> be well formed,
|
39
|
* otherwise an error will be thrown</p>
|
40
|
* @uses Mozilla's XSLTProcessor
|
41
|
* @deprecated use the XSLTProcessor instead
|
42
|
* @argument xslDoc The stylesheet to use (a DOM Document instance)
|
43
|
* @argument oResult The Document to store the transformation result
|
44
|
*/
|
45
|
XMLElement.prototype.transformNodeToObject = function(xslDoc, oResult){
|
46
|
var oDoc = document.implementation.createDocument("", "", null);
|
47
|
Sarissa.copyChildNodes(this, oDoc);
|
48
|
oDoc.transformNodeToObject(xslDoc, oResult);
|
49
|
};
|
50
|
/**
|
51
|
* <p><b>Deprecated, will be removed in 0.9.6 (use XSLTProcessor instead): </b> Extends the Document class to emulate IE's transformNodeToObject (deprecated).</p>
|
52
|
* @uses Mozilla's XSLTProcessor
|
53
|
* @deprecated use the XSLTProcessor instead
|
54
|
* @argument xslDoc The stylesheet to use (a DOM Document instance)
|
55
|
* @argument oResult The Document to store the transformation result
|
56
|
* @throws Errors that try to be informative
|
57
|
*/
|
58
|
Document.prototype.transformNodeToObject = function(xslDoc, oResult){
|
59
|
var xsltProcessor = null;
|
60
|
try{
|
61
|
xsltProcessor = new XSLTProcessor();
|
62
|
if(xsltProcessor.reset){
|
63
|
/* new nsIXSLTProcessor is available */
|
64
|
xsltProcessor.importStylesheet(xslDoc);
|
65
|
var newFragment = xsltProcessor.transformToFragment(this, oResult);
|
66
|
Sarissa.copyChildNodes(newFragment, oResult);
|
67
|
}else{
|
68
|
/* only nsIXSLTProcessorObsolete is available */
|
69
|
xsltProcessor.transformDocument(this, xslDoc, oResult, null);
|
70
|
};
|
71
|
}catch(e){
|
72
|
if(xslDoc && oResult)
|
73
|
throw "Failed to transform document. (original exception: "+e+")";
|
74
|
else if(!xslDoc)
|
75
|
throw "No Stylesheet Document was provided. (original exception: "+e+")";
|
76
|
else if(!oResult)
|
77
|
throw "No Result Document was provided. (original exception: "+e+")";
|
78
|
else if(xsltProcessor == null)
|
79
|
throw "Could not instantiate an XSLTProcessor object. (original exception: "+e+")";
|
80
|
else
|
81
|
throw e;
|
82
|
};
|
83
|
};
|
84
|
/**
|
85
|
* <p><b>Deprecated, will be removed in 0.9.6 (use XSLTProcessor instead): </b>Extends the Element class to emulate IE's transformNode (deprecated). </p>
|
86
|
* <p><b>Note </b>: The result of your transformation must be well formed,
|
87
|
* otherwise you will get an error</p>.
|
88
|
* @uses Mozilla's XSLTProcessor
|
89
|
* @deprecated use the XSLTProcessor instead
|
90
|
* @argument xslDoc The stylesheet to use (a DOM Document instance)
|
91
|
* @returns the result of the transformation serialized to an XML String
|
92
|
*/
|
93
|
XMLElement.prototype.transformNode = function(xslDoc){
|
94
|
var oDoc = document.implementation.createDocument("", "", null);
|
95
|
Sarissa.copyChildNodes(this, oDoc);
|
96
|
return oDoc.transformNode(xslDoc);
|
97
|
};
|
98
|
/**
|
99
|
* <p><b>Deprecated, will be removed in 0.9.6 (use XSLTProcessor instead): </b>Extends the Document class to emulate IE's transformNode (deprecated).</p>
|
100
|
* <p><b>Note </b>: The result of your transformation must be well formed,
|
101
|
* otherwise you will get an error</p>
|
102
|
* @uses Mozilla's XSLTProcessor
|
103
|
* @deprecated use the XSLTProcessor instead
|
104
|
* @argument xslDoc The stylesheet to use (a DOM Document instance)
|
105
|
* @returns the result of the transformation serialized to an XML String
|
106
|
*/
|
107
|
Document.prototype.transformNode = function(xslDoc){
|
108
|
var out = document.implementation.createDocument("", "", null);
|
109
|
this.transformNodeToObject(xslDoc, out);
|
110
|
var str = null;
|
111
|
try{
|
112
|
var serializer = new XMLSerializer();
|
113
|
str = serializer.serializeToString(out);
|
114
|
}catch(e){
|
115
|
throw "Failed to serialize result document. (original exception: "+e+")";
|
116
|
};
|
117
|
return str;
|
118
|
};
|
119
|
Sarissa.IS_ENABLED_TRANSFORM_NODE = true;
|
120
|
};
|
121
|
/**
|
122
|
* <p>Deprecated (use XSLTProcessor instead): Set xslt parameters.</p>
|
123
|
* <p><b>Note </b> that this method can only work for the main stylesheet and not any included/imported files.</p>
|
124
|
* @deprecated use the XSLTProcessor instead
|
125
|
* @argument oXslDoc the target XSLT DOM Document
|
126
|
* @argument sParamName the name of the XSLT parameter
|
127
|
* @argument sParamValue the value of the XSLT parameter
|
128
|
* @returns whether the parameter was set succefully
|
129
|
*/
|
130
|
Sarissa.setXslParameter = function(oXslDoc, sParamQName, sParamValue){
|
131
|
try{
|
132
|
var params = oXslDoc.getElementsByTagName(_SARISSA_IEPREFIX4XSLPARAM+"param");
|
133
|
var iLength = params.length;
|
134
|
var bFound = false;
|
135
|
var param;
|
136
|
if(sParamValue){
|
137
|
for(var i=0; i < iLength && !bFound;i++){
|
138
|
if(params[i].getAttribute("name") == sParamQName){
|
139
|
param = params[i];
|
140
|
while(param.firstChild)
|
141
|
param.removeChild(param.firstChild);
|
142
|
if(!sParamValue || sParamValue == null){
|
143
|
}else if(typeof sParamValue == "string"){
|
144
|
param.setAttribute("select", sParamValue);
|
145
|
bFound = true;
|
146
|
}else if(sParamValue.nodeName){
|
147
|
param.removeAttribute("select");
|
148
|
param.appendChild(sParamValue.cloneNode(true));
|
149
|
bFound = true;
|
150
|
}else if (sParamValue.item(0) && sParamValue.item(0).nodeType){
|
151
|
for(var j=0;j < sParamValue.length;j++)
|
152
|
if(sParamValue.item(j).nodeType)
|
153
|
param.appendChild(sParamValue.item(j).cloneNode(true));
|
154
|
bFound = true;
|
155
|
}else
|
156
|
throw "Failed to set xsl:param "+sParamQName+" (original exception: "+e+")";
|
157
|
};
|
158
|
};
|
159
|
};
|
160
|
return bFound;
|
161
|
}catch(e){
|
162
|
throw e;
|
163
|
return false;
|
164
|
};
|
165
|
};
|