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
2 changes: 1 addition & 1 deletion src/xpath/lib
49 changes: 49 additions & 0 deletions tests/xslt/call-template.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Xslt, XmlParser } from '../../src/index';

describe('xsl:call-template', () => {
let xslt: Xslt;
let xmlParser: XmlParser;

beforeEach(() => {
xslt = new Xslt();
xmlParser = new XmlParser();
});

// https://github.com/DesignLiquido/xslt-processor/issues/217
it('supports recursion, using a variable to hold the result of a nested call-template', async () => {
const xml = xmlParser.xmlParse('<FOO></FOO>');
const stylesheet = xmlParser.xmlParse(`<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template name="factorial">
<xsl:param name="number"/>
<xsl:choose>
<xsl:when test="$number = 1">
<xsl:value-of select="1"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="temp">
<xsl:call-template name="factorial">
<xsl:with-param name="number" select="$number - 1"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$number * $temp"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="FOO">
<QUX>
<xsl:attribute name="factorial">
<xsl:call-template name="factorial">
<xsl:with-param name="number" select="5"/>
</xsl:call-template>
</xsl:attribute>
</QUX>
</xsl:template>
</xsl:stylesheet>`);
const result = await xslt.xsltProcess(xml, stylesheet);
expect(result).toBe('<QUX factorial="120"/>');
});
});
Loading