Skip to content

Commit

Permalink
Adding unit test for #110.
Browse files Browse the repository at this point in the history
  • Loading branch information
leonelsanchesdasilva committed Oct 18, 2024
1 parent ea811e9 commit aa9a2a3
Showing 1 changed file with 53 additions and 13 deletions.
66 changes: 53 additions & 13 deletions tests/xslt/apply-template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,66 @@ describe('xsl:apply-template', () => {
});

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

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

const expectedOutString = `<span>Xtest1Y</span>`;
const expectedOutString = `<span>Xtest1Y</span>`;

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

const outXmlString = await xsltClass.xsltProcess(xml, xslt);

assert.equal(outXmlString, expectedOutString);
});

it.skip('https://github.com/DesignLiquido/xslt-processor/issues/110', async () => {
const xmlString = `<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
<Article>
<Title>My Article</Title>
<Authors>
<Author>Mr. Foo</Author>
<Author>Mr. Bar</Author>
</Authors>
<Body>This is my article text.</Body>
</Article>`;

const xsltString = `<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
Article - <xsl:value-of select="/Article/Title"/>
Authors: <xsl:apply-templates select="/Article/Authors/Author"/>
</xsl:template>
<xsl:template match="Author">
- <xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>`;

const expectedOutString = `Article - My Article\nAuthors:\n- Mr. Foo\n- Mr. Bar`;

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

const outXmlString = await xsltClass.xsltProcess(xml, xslt);
const outXmlString = await xsltClass.xsltProcess(xml, xslt);

assert.equal(outXmlString, expectedOutString);
});
});
assert.equal(outXmlString, expectedOutString);
});
});

0 comments on commit aa9a2a3

Please sign in to comment.