sort.html (1264B)
1 <!DOCTYPE html> 2 <link rel=match href="sort-ref.html"> 3 4 <body> 5 <div id="container"></div> 6 </body> 7 8 <script type="text/xml" id="sampleXml"> 9 <root> 10 <node id="1" /> 11 <node id="7" /> 12 <node id="3" /> 13 <node id="2" /> 14 </root> 15 </script> 16 17 <script type="text/xml" id="sampleXsl"> 18 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> 19 20 <xsl:template match="/"> 21 <xsl:apply-templates select="//node"> 22 <xsl:sort select="@id" data-type="number" /> 23 </xsl:apply-templates> 24 </xsl:template> 25 26 <xsl:template match="node"> 27 <div> 28 <xsl:value-of select="@id"/> 29 </div> 30 </xsl:template> 31 32 </xsl:stylesheet> 33 </script> 34 35 <script> 36 let parser = new DOMParser(); 37 const xslStyleSheet = parser.parseFromString(document.getElementById('sampleXsl').textContent, 'text/xml'); 38 39 const xsltProcessor = new XSLTProcessor(); 40 xsltProcessor.importStylesheet(xslStyleSheet); 41 42 parser = new DOMParser(); 43 const xmlDoc = parser.parseFromString(document.getElementById('sampleXml').textContent, 'text/xml'); 44 45 const fragment = xsltProcessor.transformToFragment(xmlDoc, document); 46 47 document.getElementById('container').appendChild(fragment); 48 </script>