8 <title>Test for EXSLT extensions
</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
14 <div id=
"content" style=
"display: none"></div>
16 <script type=
"application/javascript">
19 descr:
"Testing common:node-set",
20 expr:
"common:node-set($tree)",
22 expResult:
"<abc>def</abc>",
25 descr:
"Testing common:object-type(string)",
26 expr:
"common:object-type($string)",
30 descr:
"Testing common:object-type(number)",
31 expr:
"common:object-type($number)",
35 descr:
"Testing common:object-type(boolean)",
36 expr:
"common:object-type($boolean)",
40 descr:
"Testing common:object-type(node-set)",
41 expr:
"common:object-type($node-set)",
42 expResult:
"node-set",
45 descr:
"Testing common:object-type(tree)",
46 expr:
"common:object-type($tree)",
50 descr:
"Testing math:max",
51 expr:
"math:max(root/numbers/number)",
55 descr:
"Testing math:min",
56 expr:
"math:min(root/numbers/number)",
60 descr:
"Testing math:highest",
61 expr:
"math:highest(root/numbers/number)/@id",
65 descr:
"Testing math:lowest",
66 expr:
"math:lowest(root/numbers/number)/@id",
70 descr:
"Testing regexp:test",
71 expr:
"regexp:test('XSLT is great', 'XSLT', '')",
75 descr:
"Testing regexp:match",
76 expr:
"regexp:match('XSLT is great', 'XSL.', '')[1]",
80 descr:
"Testing regexp:replace",
81 expr:
"regexp:replace('Food is great', 'Fo.d', '', 'XSLT')",
82 expResult:
"XSLT is great",
85 descr:
"Testing sets:difference",
86 expr:
"sets:difference($i, $e)",
88 expResult:
"<city name=\"Paris\
" country=\"France\
"></city><city name=\"Madrid\
" country=\"Spain\
"></city><city name=\"Calais\
" country=\"France\
"></city>",
91 descr:
"Testing sets:distinct",
92 expr:
"strings:concat(sets:distinct(//@country))",
93 expResult:
"FranceSpainAustriaGermany",
96 descr:
"Testing sets:hasSameNode",
97 expr:
"sets:has-same-node($i, $e)",
101 descr:
"Testing sets:hasSameNode",
102 expr:
"sets:has-same-node($i, $o)",
106 descr:
"Testing sets:intersection",
107 expr:
"sets:intersection($i, $e)",
109 expResult:
"<city name=\"Vienna\
" country=\"Austria\
"></city><city name=\"Berlin\
" country=\"Germany\
"></city>",
112 descr:
"Testing sets:leading",
113 expr:
"sets:leading($i, $e)",
115 expResult:
"<city name=\"Paris\
" country=\"France\
"></city><city name=\"Madrid\
" country=\"Spain\
"></city>",
118 descr:
"Testing sets:leading",
119 expr:
"sets:leading($i, $o)",
124 descr:
"Testing sets:leading",
125 expr:
"sets:leading($i, $empty)",
127 expResult:
"<city name=\"Paris\
" country=\"France\
"></city><city name=\"Madrid\
" country=\"Spain\
"></city><city name=\"Vienna\
" country=\"Austria\
"></city><city name=\"Calais\
" country=\"France\
"></city><city name=\"Berlin\
" country=\"Germany\
"></city>",
130 descr:
"Testing sets:trailing",
131 expr:
"sets:trailing($i, $e)",
133 expResult:
"<city name=\"Calais\
" country=\"France\
"></city><city name=\"Berlin\
" country=\"Germany\
"></city>",
136 descr:
"Testing sets:trailing",
137 expr:
"sets:trailing($i, $o)",
142 descr:
"Testing sets:trailing",
143 expr:
"sets:trailing($i, $empty)",
145 expResult:
"<city name=\"Paris\
" country=\"France\
"></city><city name=\"Madrid\
" country=\"Spain\
"></city><city name=\"Vienna\
" country=\"Austria\
"></city><city name=\"Calais\
" country=\"France\
"></city><city name=\"Berlin\
" country=\"Germany\
"></city>",
148 descr:
"Testing strings:concat",
149 expr:
"strings:concat(root/numbers/number/@id)",
150 expResult:
"seveneleveneightfour",
153 descr:
"Testing strings:split",
154 expr:
"strings:split('a, simple, list', ', ')",
156 expResult:
"<token>a</token><token>simple</token><token>list</token>",
159 descr:
"Testing strings:split",
160 expr:
"strings:split('date math str')",
162 expResult:
"<token>date</token><token>math</token><token>str</token>",
165 descr:
"Testing strings:split",
166 expr:
"strings:split('foo', '')",
168 expResult:
"<token>f</token><token>o</token><token>o</token>",
171 descr:
"Testing strings:tokenize",
172 expr:
"strings:tokenize('2001-06-03T11:40:23', '-T:')",
174 expResult:
"<token>2001</token><token>06</token><token>03</token><token>11</token><token>40</token><token>23</token>",
177 descr:
"Testing strings:tokenize",
178 expr:
"strings:tokenize('date math str')",
180 expResult:
"<token>date</token><token>math</token><token>str</token>",
183 descr:
"Testing strings:tokenize",
184 expr:
"strings:tokenize('foo', '')",
186 expResult:
"<token>f</token><token>o</token><token>o</token>",
191 `
<xsl:stylesheet xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform" version=
"1.0"
192 xmlns:
common=
"http://exslt.org/common"
193 xmlns:
math=
"http://exslt.org/math"
194 xmlns:
regexp=
"http://exslt.org/regular-expressions"
195 xmlns:
sets=
"http://exslt.org/sets"
196 xmlns:
strings=
"http://exslt.org/strings">
197 <xsl:output method=
"html"/>
198 <xsl:variable name=
"tree"><abc>def
</abc></xsl:variable>
199 <xsl:variable name=
"string" select=
"'abc'"/>
200 <xsl:variable name=
"number" select=
"123"/>
201 <xsl:variable name=
"boolean" select=
"true()"/>
202 <xsl:variable name=
"node-set" select=
"//*"/>
203 <xsl:variable name=
"i" select=
"/root/sets/city[contains(@name, 'i')]" />
204 <xsl:variable name=
"e" select=
"/root/sets/city[contains(@name, 'e')]" />
205 <xsl:variable name=
"o" select=
"/root/sets/city[contains(@name, 'o')]" />
206 <xsl:variable name=
"empty" select=
"/root/sets/city[contains(@name, 'x')]" />
207 <xsl:template match=
"/">
208 ${tests.map(({expr, useCopyOf}, i) =
> `
<div id=
"${i}"><xsl:${useCopyOf ?
"copy-of" :
"value-of"}
select=
"${expr}"/></div>`).join(
"\n")}
212 let styleDoc = new DOMParser().parseFromString(style,
"text/xml");
216 <number id=
"seven">7</number>
217 <number id=
"eleven">11</number>
218 <number id=
"eight">8</number>
219 <number id=
"four">4</number>
222 <city name=
"Paris" country=
"France" />
223 <city name=
"Madrid" country=
"Spain" />
224 <city name=
"Vienna" country=
"Austria" />
225 <city name=
"Barcelona" country=
"Spain" />
226 <city name=
"Salzburg" country=
"Austria" />
227 <city name=
"Bonn" country=
"Germany" />
228 <city name=
"Lyon" country=
"France" />
229 <city name=
"Hannover" country=
"Germany" />
230 <city name=
"Calais" country=
"France" />
231 <city name=
"Berlin" country=
"Germany" />
234 let originalDoc = new DOMParser().parseFromString(data,
"text/xml");
236 let processor = new XSLTProcessor();
237 processor.importStylesheet(styleDoc);
239 let fragment = processor.transformToFragment(originalDoc, document);
241 tests.forEach(({descr, expResult}, i) =
> {
242 let result = fragment.getElementById(i);
243 is(result.innerHTML, expResult, descr);