tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

document-function.window.js (1481B)


      1 const xmlString = `
      2 <foo>
      3  <bar>x</bar>
      4  <bar>y</bar>
      5 </foo>
      6 `;
      7 const xsltString = `
      8 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      9  <xsl:template match="/">
     10    <result>
     11      <xsl:apply-templates select="document('resources/test.xml')//static" />
     12      <xsl:apply-templates select="foo" />
     13    </result>
     14  </xsl:template>
     15  <xsl:template match="static">
     16    <failure />
     17  </xsl:template>
     18  <xsl:template match="foo">
     19    <success />
     20  </xsl:template>
     21 </xsl:stylesheet>
     22 `;
     23 const parser = new DOMParser();
     24 
     25 const xmlDoc = parser.parseFromString(xmlString, "application/xml");
     26 const xsltDoc = parser.parseFromString(xsltString, "application/xml");
     27 const xsltProcessor = new XSLTProcessor();
     28 
     29 xsltProcessor.importStylesheet(xsltDoc);
     30 
     31 test(() => {
     32  const resultFrag = xsltProcessor.transformToFragment(xmlDoc, document);
     33  assert_equals(resultFrag.firstChild.localName, "result");
     34  assert_true(Array.prototype.every.call(resultFrag.firstChild.children,
     35                                         (e) => e.localName == "success"));
     36 }, `xsl:document function disabled in transformToFragment`);
     37 
     38 test(() => {
     39  const resultDoc = xsltProcessor.transformToDocument(xmlDoc);
     40  assert_equals(resultDoc.documentElement.localName, "result");
     41  assert_true(Array.prototype.every.call(resultDoc.documentElement.children,
     42                                         (e) => e.localName == "success"));
     43 }, `xsl:document function disabled in transformToDocument`);