4 <title>Test for setParameter/getParameter
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
10 <div id=
"content" style=
"display: none"><p id=
"number">123</p><p id=
"string">abc
</p></div>
13 let processor
= new XSLTProcessor();
15 processor
.setParameter(null, "test", "hello");
16 is(processor
.getParameter(null, "test"), "hello", "null namespace works");
18 processor
.setParameter("foo", "bar", "foobar");
19 is(processor
.getParameter("foo", "bar"), "foobar", "non-null namespace works");
21 processor
.setParameter(null, "test", 123);
22 is(processor
.getParameter(null, "test"), 123, "number value works");
24 processor
.removeParameter(null, "test");
25 is(processor
.getParameter(null, "test"), null, "removeParameter works");
27 is(processor
.getParameter(null, "not-here"), null, "nonexistant parameter");
29 let parser
= new DOMParser();
31 `<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
32 xmlns:exslt="http://exslt.org/common">
33 <xsl:output method="html" />
34 <xsl:param name="test" />
35 <xsl:template match="/">
36 <p id="result"><xsl:value-of select="exslt:object-type($test)" /></p>
39 const styleDoc
= parser
.parseFromString(style
, "text/xml");
41 const xml
= `<root />`;
42 const sourceDoc
= parser
.parseFromString(xml
, "text/xml");
44 function checkParameter(value
, parameter
) {
45 let valueType
= typeof value
;
50 is(typeof parameter
, valueType
, "Parameter has right type");
51 is(parameter
, value
, "Parameter has right value");
54 if (value
instanceof Array
|| value
instanceof NodeList
) {
55 ok(parameter
instanceof Array
, "Parameter has right type");
56 ok(parameter
.length
== value
.length
&&
57 parameter
.every((p
, i
) => value
[i
] === p
),
58 "Parameter has right value");
62 if (value
instanceof Node
) {
63 is(parameter
, value
, "Parameter has right value");
67 if (value
instanceof XPathResult
) {
68 ok(parameter
instanceof XPathResult
, "Parameter has right type");
69 is(parameter
.resultType
, value
.resultType
, "Parameter has right inner type");
71 switch (value
.resultType
) {
72 case XPathResult
.NUMBER_TYPE
:
73 valueProperty
= "numberValue";
75 case XPathResult
.BOOLEAN_TYPE
:
76 valueProperty
= "booleanValue";
78 case XPathResult
.STRING_TYPE
:
79 valueProperty
= "stringValue";
81 case XPathResult
.FIRST_ORDERED_NODE_TYPE
:
82 valueProperty
= "singleNodeValue";
85 ok(false, "Unexpected inner type");
88 is(parameter
[valueProperty
], value
[valueProperty
], "Parameter has right value");
92 ok(false, "Unexpected value");
95 function getXSLTType(value
) {
96 let valueType
= typeof value
;
103 if (value
instanceof Array
|| value
instanceof Node
|| value
instanceof NodeList
) {
106 if (value
instanceof XPathResult
) {
107 switch (value
.resultType
) {
108 case XPathResult
.NUMBER_TYPE
:
110 case XPathResult
.BOOLEAN_TYPE
:
112 case XPathResult
.STRING_TYPE
:
114 case XPathResult
.FIRST_ORDERED_NODE_TYPE
:
119 ok(false, "Unexpected value");
120 throw new Error("Unexpected value");
123 function testParameter(value
) {
124 let testProcessor
= new XSLTProcessor();
126 testProcessor
.setParameter(null, "test", value
);
127 let parameter
= testProcessor
.getParameter(null, "test");
129 checkParameter(value
, parameter
);
131 testProcessor
.importStylesheet(styleDoc
);
133 let fragment
= testProcessor
.transformToFragment(sourceDoc
, document
);
136 fragment
.getElementById("result").textContent
,
138 "Global parameter has right type in XSLT."
144 testParameter("abcd");
145 testParameter([document
]);
146 testParameter(document
.documentElement
.childNodes
);
147 testParameter(document
);
148 testParameter(document
.evaluate("id('number')", document
, null, XPathResult
.NUMBER_TYPE
));
149 testParameter(document
.evaluate("/", document
, null, XPathResult
.BOOLEAN_TYPE
));
150 testParameter(document
.evaluate("id('string')", document
, null, XPathResult
.STRING_TYPE
));
152 document
.evaluate("/", document
, null, XPathResult
.FIRST_ORDERED_NODE_TYPE
)