-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
Environment
- node.js: 23.7.0
- xslt-processor: 3.3.1
Problem Description
When calling apply-templates
with with-param
child. Resulting param in the template remains empty.
Example
XML:
<?xml version="1.0" encoding="UTF-8"?>
<catalog status="WIP">
<book>
<title>Learning XML</title>
<author>John Doe</author>
</book>
<book>
<title>Mastering XSLT</title>
<author>Jane Smith</author>
</book>
</catalog>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Book Catalog</title>
</head>
<body>
<h1>Book Catalog</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="catalog">
<ul>
<xsl:apply-templates select="book">
<xsl:with-param name="prefix" select="@status"/>
</xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="book">
<xsl:param name="prefix" />
<li>
<strong>
<xsl:value-of select="$prefix"/> - <xsl:value-of select="title"/>
</strong>
<br/>
<span>by <xsl:value-of select="author"/></span>
</li>
</xsl:template>
</xsl:stylesheet>
Result:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Book Catalog</title>
</head>
<body>
<h1>Book Catalog</h1>
<ul>
<li><strong> - Learning XML</strong><br><span>by John Doe</span></li>
<li><strong> - Mastering XSLT</strong><br><span>by Jane Smith</span></li>
</ul>
</body>
</html>
Expected:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Book Catalog</title>
</head>
<body>
<h1>Book Catalog</h1>
<ul>
<li><strong>WIP - Learning XML</strong><br><span>by John Doe</span></li>
<li><strong>WIP - Mastering XSLT</strong><br><span>by Jane Smith</span></li>
</ul>
</body>
</html>
Code:
import { Xslt, XmlParser } from 'xslt-processor';
const xmlString = `<?xml version="1.0" encoding="UTF-8"?>
<catalog status="WIP">
<book>
<title>Learning XML</title>
<author>John Doe</author>
</book>
<book>
<title>Mastering XSLT</title>
<author>Jane Smith</author>
</book>
</catalog>`;
const xsltString = `<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Book Catalog</title>
</head>
<body>
<h1>Book Catalog</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="catalog">
<ul>
<xsl:apply-templates select="book">
<xsl:with-param name="prefix" select="@status"/>
</xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="book">
<xsl:param name="prefix" />
<li>
<strong>
<xsl:value-of select="$prefix"/> - <xsl:value-of select="title"/>
</strong>
<br/>
<span>by <xsl:value-of select="author"/></span>
</li>
</xsl:template>
</xsl:stylesheet>`;
const parser = new XmlParser();
const transformer = new Xslt();
const xmlDoc = parser.xmlParse(xmlString);
const xsltDoc = parser.xmlParse(xsltString);
const htmlResult = await transformer.xsltProcess(xmlDoc, xsltDoc);
console.log(htmlResult);
Metadata
Metadata
Assignees
Labels
No labels