Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/xpath/xpath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,11 +988,11 @@ export class XPath {
return;
}

const sortlist = [];
const sortList = [];

for (let i = 0; i < context.contextSize(); ++i) {
const node = context.nodeList[i];
const sortitem = {
const sortItem = {
node,
key: []
};
Expand All @@ -1007,7 +1007,7 @@ export class XPath {
} else if (s.type === 'number') {
evalue = value.numberValue();
}
sortitem.key.push({
sortItem.key.push({
value: evalue,
order: s.order
});
Expand All @@ -1016,19 +1016,19 @@ export class XPath {
// Make the sort stable by adding a lowest priority sort by
// id. This is very convenient and furthermore required by the
// spec ([XSLT] - Section 10 Sorting).
sortitem.key.push({
sortItem.key.push({
value: i,
order: 'ascending'
});

sortlist.push(sortitem);
sortList.push(sortItem);
}

sortlist.sort(this.xPathSortByKey);
sortList.sort(this.xPathSortByKey);

const nodes = [];
for (let i = 0; i < sortlist.length; ++i) {
const node = sortlist[i].node;
for (let i = 0; i < sortList.length; ++i) {
const node = sortList[i].node;
node.siblingPosition = i;
nodes.push(node);
}
Expand Down
8 changes: 5 additions & 3 deletions src/xslt/xslt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ export class Xslt {
* sort order specified by xsl:sort child nodes of the current
* template node. This happens before the operation specified by the
* current template node is executed.
* @param context TODO
* @param template TODO
* @param context The expression context.
* @param template The template node.
* @todo case-order is not implemented.
*/
protected xsltSort(context: ExprContext, template: XNode) {
Expand Down Expand Up @@ -722,7 +722,9 @@ export class Xslt {
if (node.outputNode === undefined || node.outputNode === null || context.outputDepth > 0) {
newNode = domCreateElement(this.outputDocument, template.nodeName);
newNode.siblingPosition = node.siblingPosition;
node.outputNode = newNode;
if (context.outputDepth === 0) {
node.outputNode = newNode;
}
} else {
newNode = node.outputNode;
}
Expand Down
49 changes: 49 additions & 0 deletions tests/xml/xml-to-html.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import assert from 'assert';
import { XmlParser } from "../../src/dom";
import { Xslt } from '../../src/xslt';

describe('XML to HTML', () => {
it('Issue 74', () => {
const xmlString = `<?xml version="1.0" encoding="UTF-8"?>
<problem/>`;

const xsltString = `<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/problem">
<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>
<div>
<div>should be below table rite??!</div>
</div>
</xsl:template>
</xsl:stylesheet>`;

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>`;

const xsltClass = new Xslt();
const xmlParser = new XmlParser();
const xml = xmlParser.xmlParse(xmlString);
const xslt = xmlParser.xmlParse(xsltString);
const outXmlString = xsltClass.xsltProcess(
xml,
xslt
);

// console.log(outXmlString);
assert.equal(outXmlString, expectedOutHtml);
});
});