Skip to content

Commit aa9a2a3

Browse files
Adding unit test for #110.
1 parent ea811e9 commit aa9a2a3

File tree

1 file changed

+53
-13
lines changed

1 file changed

+53
-13
lines changed

tests/xslt/apply-template.test.ts

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,66 @@ describe('xsl:apply-template', () => {
4040
});
4141

4242
it.skip('XSLT template with text on both sides', async () => {
43-
const xmlString = `<root>
44-
<test name="test1">This text lost</test>
45-
</root>`;
43+
const xmlString = `<root>
44+
<test name="test1">This text lost</test>
45+
</root>`;
4646

47-
const xsltString = `<?xml version="1.0"?>
47+
const xsltString = `<?xml version="1.0"?>
4848
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
4949
<xsl:template match="/">
5050
<span>X<xsl:value-of select="//test/@name" />Y</span>
5151
</xsl:template>
5252
</xsl:stylesheet>`;
5353

54-
const expectedOutString = `<span>Xtest1Y</span>`;
54+
const expectedOutString = `<span>Xtest1Y</span>`;
55+
56+
const xsltClass = new Xslt();
57+
const xmlParser = new XmlParser();
58+
const xml = xmlParser.xmlParse(xmlString);
59+
const xslt = xmlParser.xmlParse(xsltString);
60+
61+
const outXmlString = await xsltClass.xsltProcess(xml, xslt);
62+
63+
assert.equal(outXmlString, expectedOutString);
64+
});
65+
66+
it.skip('https://github.com/DesignLiquido/xslt-processor/issues/110', async () => {
67+
const xmlString = `<?xml version="1.0"?>
68+
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
69+
<Article>
70+
<Title>My Article</Title>
71+
<Authors>
72+
<Author>Mr. Foo</Author>
73+
<Author>Mr. Bar</Author>
74+
</Authors>
75+
<Body>This is my article text.</Body>
76+
</Article>`;
77+
78+
const xsltString = `<?xml version="1.0"?>
79+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
80+
81+
<xsl:output method="text"/>
82+
83+
<xsl:template match="/">
84+
Article - <xsl:value-of select="/Article/Title"/>
85+
Authors: <xsl:apply-templates select="/Article/Authors/Author"/>
86+
</xsl:template>
87+
88+
<xsl:template match="Author">
89+
- <xsl:value-of select="." />
90+
</xsl:template>
91+
92+
</xsl:stylesheet>`;
93+
94+
const expectedOutString = `Article - My Article\nAuthors:\n- Mr. Foo\n- Mr. Bar`;
5595

56-
const xsltClass = new Xslt();
57-
const xmlParser = new XmlParser();
58-
const xml = xmlParser.xmlParse(xmlString);
59-
const xslt = xmlParser.xmlParse(xsltString);
96+
const xsltClass = new Xslt();
97+
const xmlParser = new XmlParser();
98+
const xml = xmlParser.xmlParse(xmlString);
99+
const xslt = xmlParser.xmlParse(xsltString);
60100

61-
const outXmlString = await xsltClass.xsltProcess(xml, xslt);
101+
const outXmlString = await xsltClass.xsltProcess(xml, xslt);
62102

63-
assert.equal(outXmlString, expectedOutString);
64-
});
65-
});
103+
assert.equal(outXmlString, expectedOutString);
104+
});
105+
});

0 commit comments

Comments
 (0)