Skip to content

Commit ac6ad4d

Browse files
- Improving interactive tests;
- Adding unit test with problematic case to be resolved in the future.
1 parent 88ce51e commit ac6ad4d

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

interactive-tests/xslt.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</script>
3636
</head>
3737
<body onload="cleanxml()">
38-
<form onsubmit="test_xslt()">
38+
<form>
3939
<table>
4040
<tr>
4141
<td>
@@ -51,10 +51,10 @@
5151
<textarea id="xslt" cols="40" rows="10">
5252
<xsl:stylesheet>
5353
<xsl:template match="/">
54-
<xsl:apply-templates select="page/message"/>
54+
<xsl:apply-templates select="/page/message"/>
5555
</xsl:template>
5656

57-
<xsl:template match="page/message">
57+
<xsl:template match="/page/message">
5858
<div style="color:green">
5959
<xsl:value-of select="."/>
6060
</div>
@@ -65,7 +65,7 @@
6565
</tr>
6666
<tr>
6767
<td colspan="2">
68-
<input type="submit" value="process"/>
68+
<input type="button" value="process" onclick="test_xslt()"/>
6969
</td>
7070
</tr>
7171
<tr>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint-disable no-undef */
2+
import assert from 'assert';
3+
4+
import { Xslt } from '../src/xslt';
5+
import { XmlParser } from '../src/dom';
6+
7+
describe('Interactive Tests Examples', () => {
8+
// TODO: Per https://github.com/DesignLiquido/xslt-processor/issues/116, while debugging
9+
// this test, we've found that `<xsl:apply-templates>` with a `select` attribute +
10+
// `<xsl:template>` does not work well for relative XPath (it works for absolute XPath).
11+
// The problem happens because the implementation calls the traditional `<xsl:template>`,
12+
// which it tries to re-select nodes that are already selected in the expression context by
13+
// `<xsl:apply-templates>`. Instead, it should "select the appropriate template", as mentioned
14+
// at https://www.w3.org/TR/xslt-10/#section-Applying-Template-Rules and
15+
// https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms256184(v=vs.100),
16+
// and process each child by the selected template.
17+
it.skip('Former xslt.html', async () => {
18+
const xmlString = (
19+
`<page>
20+
<message>
21+
Hello World.
22+
</message>
23+
</page>`
24+
);
25+
26+
const xsltString =
27+
`<?xml version="1.0"?>
28+
<xsl:stylesheet>
29+
<xsl:template match="/">
30+
<xsl:apply-templates select="page/message"/>
31+
</xsl:template>
32+
33+
<xsl:template match="page/message">
34+
<div style="color:green">
35+
<xsl:value-of select="."/>
36+
</div>
37+
</xsl:template>
38+
</xsl:stylesheet>`;
39+
40+
const xsltClass = new Xslt();
41+
const xmlParser = new XmlParser();
42+
const xml = xmlParser.xmlParse(xmlString);
43+
const xslt = xmlParser.xmlParse(xsltString);
44+
45+
const outXmlString = await xsltClass.xsltProcess(xml, xslt);
46+
47+
assert.ok(outXmlString);
48+
});
49+
});

0 commit comments

Comments
 (0)