|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 Test EXSLT Regular Expression Extension |
|
5 http://www.exslt.org/regexp/index.html |
|
6 --> |
|
7 <head> |
|
8 <title>Test for EXSLT Regular Expression Extensions</title> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"></div> |
|
15 <pre id="test"> |
|
16 <script type="application/javascript"> |
|
17 var tests = [ |
|
18 { descr: "Testing regexp:test", |
|
19 expr: "regexp:test('XSLT is great', 'XSLT', '')", |
|
20 expResult: "true" }, |
|
21 |
|
22 { descr: "Testing regexp:match", |
|
23 expr: "regexp:match('XSLT is great', 'XSL.', '')[1]", |
|
24 expResult: "XSLT" }, |
|
25 |
|
26 { descr: "Testing regexp:replace", |
|
27 expr: "regexp:replace('Food is great', 'Fo.d', '', 'XSLT')", |
|
28 expResult: "XSLT is great" } |
|
29 ]; |
|
30 |
|
31 for (test of tests) { |
|
32 var style = |
|
33 '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ' + |
|
34 'xmlns:regexp="http://exslt.org/regular-expressions" '+ |
|
35 'version="1.0">' + |
|
36 '<xsl:output method="html"/>' + |
|
37 '<xsl:template match="/">' + |
|
38 '<xsl:value-of select="'+test.expr+'" /> ' + |
|
39 '</xsl:template>' + |
|
40 '</xsl:stylesheet>'; |
|
41 var styleDoc = new DOMParser().parseFromString (style, "text/xml"); |
|
42 |
|
43 var data = '<root/>'; |
|
44 var originalDoc = new DOMParser().parseFromString(data, "text/xml"); |
|
45 |
|
46 var processor = new XSLTProcessor(); |
|
47 processor.importStylesheet(styleDoc); |
|
48 |
|
49 var fragment = processor.transformToFragment(originalDoc, document); |
|
50 var content = document.getElementById("content"); |
|
51 content.appendChild(fragment); |
|
52 is(content.innerHTML, test.expResult, test.descr); |
|
53 |
|
54 content.innerHTML = ''; |
|
55 } |
|
56 |
|
57 </script> |
|
58 </pre> |
|
59 </body> |
|
60 </html> |