summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/xslt/sort.html
blob: 631c3edd6aee36e66f7aa10aef7cdc5c2f520e43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<link rel=match href="sort-ref.html">

<body>
  <div id="container"></div>
</body>

<script type="text/xml" id="sampleXml">
  <root>
    <node id="1" />
    <node id="7" />
    <node id="3" />
    <node id="2" />
  </root>
</script>

<script type="text/xml" id="sampleXsl">
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

    <xsl:template match="/">
      <xsl:apply-templates select="//node">
        <xsl:sort select="@id" data-type="number" />
      </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="node">
      <div>
        <xsl:value-of select="@id"/>
      </div>
    </xsl:template>

  </xsl:stylesheet>
</script>

<script>
  let parser = new DOMParser();
  const xslStyleSheet = parser.parseFromString(document.getElementById('sampleXsl').textContent, 'text/xml');

  const xsltProcessor = new XSLTProcessor();
  xsltProcessor.importStylesheet(xslStyleSheet);

  parser = new DOMParser();
  const xmlDoc = parser.parseFromString(document.getElementById('sampleXml').textContent, 'text/xml');

  const fragment = xsltProcessor.transformToFragment(xmlDoc, document);

  document.getElementById('container').appendChild(fragment);
</script>