From 90f52213d9d5fc5e85bd0cf34a7c17a57aac66d9 Mon Sep 17 00:00:00 2001 From: Leonel Sanches da Silva <53848829+leonelsanchesdasilva@users.noreply.github.com> Date: Wed, 4 Feb 2026 08:55:34 -0800 Subject: [PATCH 1/2] Fixing issues reported at #160 and #161: - Issue 160 Loop: Verifies that `` inside a loop renders unique content for each item. - Issue 161 Order: Verifies that mixed `` and literal tags appear in the correct interleaved order. --- src/xslt/xslt.ts | 5 ++- tests/gh_issues_160_161.test.tsx | 74 ++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 tests/gh_issues_160_161.test.tsx diff --git a/src/xslt/xslt.ts b/src/xslt/xslt.ts index 9b6a090..173c6a9 100644 --- a/src/xslt/xslt.ts +++ b/src/xslt/xslt.ts @@ -1332,10 +1332,13 @@ export class Xslt { // node.transformedNodeName = name; + // Fix for Issue 161: Set siblingPosition to preserve document order + node.siblingPosition = (output || this.outputDocument).childNodes.length; + domAppendChild(output || this.outputDocument, node); // The element becomes the output node of the source node. // context.nodeList[context.position].outputNode = node; - const clonedContext = context.clone(undefined, 0); + const clonedContext = context.clone(); await this.xsltChildNodes(clonedContext, template, node); } diff --git a/tests/gh_issues_160_161.test.tsx b/tests/gh_issues_160_161.test.tsx new file mode 100644 index 0000000..ba5e639 --- /dev/null +++ b/tests/gh_issues_160_161.test.tsx @@ -0,0 +1,74 @@ +/* eslint-disable no-undef */ +import assert from 'assert'; + +import { Xslt } from '../src/xslt'; +import { XmlParser } from '../src/dom'; + +describe('Issues 160 and 161', () => { + + // Issue 160 + it('Issue 160: xsl:element inside for-each should use correct context node', async () => { + const xmlString = ` + + Item 1 + Item 2 + `; + + const xsltString = ` + + + + + + + + + + + `; + + const expectedOutString = `Item 1Item 2`; + + 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); + + // Normalize whitespace for comparison if needed, but for now exact match + assert.equal(outXmlString.replace(/\s+/g, ''), expectedOutString.replace(/\s+/g, '')); + }); + + // Issue 161 + it('Issue 161: Mixing xsl:element and literal tags should preserve order', async () => { + const xmlString = ` + + Item 1 + Item 2 + `; + + const xsltString = ` + + + + + Gen + Lit + + + + `; + + // Expected: Interleaved + const expectedOutString = `Gen 1Lit 1Gen 2Lit 2`; + + 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); + + console.log('Issue 161 Output:', outXmlString); + assert.equal(outXmlString.replace(/\s+/g, ''), expectedOutString.replace(/\s+/g, '')); + }); +}); From 1c68ad1588a730e9078518d4945d8e91b79e452d Mon Sep 17 00:00:00 2001 From: Leonel Sanches da Silva <53848829+leonelsanchesdasilva@users.noreply.github.com> Date: Wed, 4 Feb 2026 09:04:47 -0800 Subject: [PATCH 2/2] Update tests/gh_issues_160_161.test.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- tests/gh_issues_160_161.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/gh_issues_160_161.test.tsx b/tests/gh_issues_160_161.test.tsx index ba5e639..66f3917 100644 --- a/tests/gh_issues_160_161.test.tsx +++ b/tests/gh_issues_160_161.test.tsx @@ -68,7 +68,7 @@ describe('Issues 160 and 161', () => { const xslt = xmlParser.xmlParse(xsltString); const outXmlString = await xsltClass.xsltProcess(xml, xslt); - console.log('Issue 161 Output:', outXmlString); + // console.log('Issue 161 Output:', outXmlString); assert.equal(outXmlString.replace(/\s+/g, ''), expectedOutString.replace(/\s+/g, '')); }); });