Skip to content

Commit

Permalink
Adding unit test reported in #108.
Browse files Browse the repository at this point in the history
  • Loading branch information
leonelsanchesdasilva committed Oct 16, 2024
1 parent e051c7c commit a64644e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/xslt/apply-template.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import assert from 'assert';

import { Xslt } from '../../src/xslt';
import { XmlParser } from '../../src/dom';

describe('xsl:apply-template', () => {
/**
* Returning: '<div><h2>test1</h2><p> hello<span>replaced text</span></p></div>'
* Expected is: '<div><h2>test1</h2><p>This is <span>replaced text</span> hello</p></div>'
*/
it.skip('XSLT apply-template inside text test (https://github.com/DesignLiquido/xslt-processor/issues/108)', async () => {
const xmlString = `<root>
<test name="test1">This is <repl>text</repl> hello</test>
</root>`;

const xsltString = `<?xml version="1.0"?>
<xsl:stylesheet version="1.0">
<xsl:template match="repl">
<span>replaced <xsl:value-of select="." /></span>
</xsl:template>
<xsl:template match="/">
<div>
<h2><xsl:value-of select="test/@name" /></h2>
<p><xsl:apply-templates select="test/node()" /></p>
</div>
</xsl:template>
</xsl:stylesheet>`;

const expectedOutString = `<div><h2>test1</h2><p>This is <span>replaced text</span> hello</p></div>`;

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);
// assert.ok(outXmlString);
});
});

0 comments on commit a64644e

Please sign in to comment.