File tree Expand file tree Collapse file tree 3 files changed +62
-11
lines changed
Expand file tree Collapse file tree 3 files changed +62
-11
lines changed Original file line number Diff line number Diff line change @@ -988,11 +988,11 @@ export class XPath {
988988 return ;
989989 }
990990
991- const sortlist = [ ] ;
991+ const sortList = [ ] ;
992992
993993 for ( let i = 0 ; i < context . contextSize ( ) ; ++ i ) {
994994 const node = context . nodeList [ i ] ;
995- const sortitem = {
995+ const sortItem = {
996996 node,
997997 key : [ ]
998998 } ;
@@ -1007,7 +1007,7 @@ export class XPath {
10071007 } else if ( s . type === 'number' ) {
10081008 evalue = value . numberValue ( ) ;
10091009 }
1010- sortitem . key . push ( {
1010+ sortItem . key . push ( {
10111011 value : evalue ,
10121012 order : s . order
10131013 } ) ;
@@ -1016,19 +1016,19 @@ export class XPath {
10161016 // Make the sort stable by adding a lowest priority sort by
10171017 // id. This is very convenient and furthermore required by the
10181018 // spec ([XSLT] - Section 10 Sorting).
1019- sortitem . key . push ( {
1019+ sortItem . key . push ( {
10201020 value : i ,
10211021 order : 'ascending'
10221022 } ) ;
10231023
1024- sortlist . push ( sortitem ) ;
1024+ sortList . push ( sortItem ) ;
10251025 }
10261026
1027- sortlist . sort ( this . xPathSortByKey ) ;
1027+ sortList . sort ( this . xPathSortByKey ) ;
10281028
10291029 const nodes = [ ] ;
1030- for ( let i = 0 ; i < sortlist . length ; ++ i ) {
1031- const node = sortlist [ i ] . node ;
1030+ for ( let i = 0 ; i < sortList . length ; ++ i ) {
1031+ const node = sortList [ i ] . node ;
10321032 node . siblingPosition = i ;
10331033 nodes . push ( node ) ;
10341034 }
Original file line number Diff line number Diff line change @@ -565,8 +565,8 @@ export class Xslt {
565565 * sort order specified by xsl:sort child nodes of the current
566566 * template node. This happens before the operation specified by the
567567 * current template node is executed.
568- * @param context TODO
569- * @param template TODO
568+ * @param context The expression context.
569+ * @param template The template node.
570570 * @todo case-order is not implemented.
571571 */
572572 protected xsltSort ( context : ExprContext , template : XNode ) {
@@ -722,7 +722,9 @@ export class Xslt {
722722 if ( node . outputNode === undefined || node . outputNode === null || context . outputDepth > 0 ) {
723723 newNode = domCreateElement ( this . outputDocument , template . nodeName ) ;
724724 newNode . siblingPosition = node . siblingPosition ;
725- node . outputNode = newNode ;
725+ if ( context . outputDepth === 0 ) {
726+ node . outputNode = newNode ;
727+ }
726728 } else {
727729 newNode = node . outputNode ;
728730 }
Original file line number Diff line number Diff line change 1+ import assert from 'assert' ;
2+ import { XmlParser } from "../../src/dom" ;
3+ import { Xslt } from '../../src/xslt' ;
4+
5+ describe ( 'XML to HTML' , ( ) => {
6+ it ( 'Issue 74' , ( ) => {
7+ const xmlString = `<?xml version="1.0" encoding="UTF-8"?>
8+ <problem/>` ;
9+
10+ const xsltString = `<?xml version="1.0" encoding="utf-8"?>
11+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
12+ <xsl:template match="/problem">
13+ <div>
14+ <div>
15+ <table>
16+ <tr>
17+ <th>A</th>
18+ <th>B</th>
19+ <th>C</th>
20+ </tr>
21+ <tr>
22+ <td>AA</td>
23+ <td>BB</td>
24+ <td>CC</td>
25+ </tr>
26+ </table>
27+ </div>
28+ </div>
29+ <div>
30+ <div>should be below table rite??!</div>
31+ </div>
32+ </xsl:template>
33+ </xsl:stylesheet>` ;
34+
35+ const expectedOutHtml = `<div><div><table><tr><th>A</th><th>B</th><th>C</th></tr><tr><td>AA</td><td>BB</td><td>CC</td></tr></table></div><div>should be below table rite??!</div></div>` ;
36+
37+ const xsltClass = new Xslt ( ) ;
38+ const xmlParser = new XmlParser ( ) ;
39+ const xml = xmlParser . xmlParse ( xmlString ) ;
40+ const xslt = xmlParser . xmlParse ( xsltString ) ;
41+ const outXmlString = xsltClass . xsltProcess (
42+ xml ,
43+ xslt
44+ ) ;
45+
46+ // console.log(outXmlString);
47+ assert . equal ( outXmlString , expectedOutHtml ) ;
48+ } ) ;
49+ } ) ;
You can’t perform that action at this time.
0 commit comments