From 3fec78da51f40bfbc4241bee18962ea548700774 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Tue, 9 Jun 2026 02:58:34 +0200 Subject: [PATCH] feat(xslt): implement xsl:output cdata-section-elements The text content of the named result elements is emitted in CDATA sections rather than escaped: the result tree's text children of those elements are converted to CDATA nodes before serialization, leaving nested and other elements unaffected. Part of #82. --- CHANGELOG.md | 1 + Sources/XSLT/XSLTModel.swift | 5 ++++ Sources/XSLT/XSLTParser.swift | 1 + Sources/XSLT/XSLTTransform.swift | 29 +++++++++++++++++--- Tests/XSLTCDATASectionTests.swift | 44 +++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 Tests/XSLTCDATASectionTests.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 89b8832..b920117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- XSLT `xsl:output cdata-section-elements` (#82). The text content of the named result elements is emitted in `` sections instead of escaped, leaving nested elements and other elements unaffected. - XSLT `xsl:output` `doctype-public`/`doctype-system` (#82). When either is set, a `` for the result's root element (PUBLIC when both are given, SYSTEM otherwise) is emitted before the serialized output, for XML and HTML methods. - XSLT `key()` over a node-set second argument (#82). `key(name, node-set)` (including `key('k', .)`) now unions the matches for every node's string value and de-duplicates, rather than using only the first node's string value. - XSLT `method="html"` output (#82). An `xsl:output method="html"` result is now serialized by the HTML rules (void elements like `
` emitted without a self-closing slash, raw-text elements like `"), "") + #expect(out == "") + } + + @Test("An element not named keeps escaped text") + func test_notNamed() throws { + let out = try transform(style("script", "a < b"), "") + #expect(out == "a < b") + } + + @Test("Only the named element's own text is wrapped, not nested elements") + func test_nestedUnaffected() throws { + let out = try transform(style("outer", "xy < z"), "") + #expect(out == "y < z") + } + + @Test("Multiple element names can be listed") + func test_multiple() throws { + let out = try transform(style("a b", "1 & 23 & 4"), "") + #expect(out == "") + } +}