dom/xslt/tests/mochitest/test_exslt_regex.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial