feat(xslt): global variable scope and precedence, NCName:* name tests
A top-level variable evaluates with every previously evaluated global in scope, so referencing an earlier top-level param works, directly or via call-template; same-name globals resolve by import precedence with the last fold winning, so a later sibling import beats an earlier one; the stylesheet fold uniformly favors later contributions, matching the post-order precedence model; and the XPath compiler accepts NCName:* name tests, matching any name in the prefix's namespace at the -0.25 default priority, so @ped:* outranks @*. Xalan baseline 144 -> 134 (variable 10 -> 5, conflictres 8 -> 5).
This commit is contained in:
parent
ef4e7afa7a
commit
6174c7bde1
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- Globals, prefix wildcards, fifteenth xalan burn-down (#130): a top-level variable now evaluates with every previously evaluated global in scope, so a variable whose body references an earlier top-level param (directly or via call-template) resolves; same-name globals resolve by import precedence (folds happen in precedence order and the last same-name entry wins, so a later sibling import beats an earlier one and the importing sheet beats both); the stylesheet fold uniformly favors later contributions for attribute-set definitions, decimal formats, namespace aliases, and output settings, matching the post-order precedence model; and the XPath compiler accepts the `NCName:*` name-test form, matching any name in the prefix's namespace (bound by URI, falling back to the in-document prefix string) at its -0.25 default priority, so `@ped:*` outranks `@*`. Three unit tests pin the behaviors. Baseline 144 to 134 (variable 10 to 5, conflictres 8 to 5).
|
||||
- Import precedence and relative composition, fourteenth xalan burn-down (#130): import precedences are assigned in post-order over the import tree, so sibling imports are distinct (later higher) and every unit sits above its own imports; apply-imports searches only the current template's stylesheet's own import subtree per 5.6 (templates carry their unit's precedence range), falling back to the built-in rule when that unit imports nothing; an included stylesheet's declarations join the including unit at its precedence while its imports join the import list; and include/import hrefs resolve against the including stylesheet's own URI, so nested relative chains load correctly. Also fixed along the way: an included document's tree was only weakly referenced once flattened, so its ancestor chain (xmlns declarations, exclusions in scope) could disappear before its templates were parsed. Two unit tests pin apply-imports scoping and relative chains. Baseline 159 to 144 (reluri 11 to 3, impincl 9 to 2).
|
||||
- Attribute sets, copied namespaces, html booleans, loader entities, thirteenth xalan burn-down (#130): same-name `xsl:attribute-set` declarations merge as ordered definitions per 7.1.4 (each expands its used sets before its own attributes, a later definition's attributes winning); `xsl:copy` of an element carries the source element's in-scope namespace nodes per 7.5 (the fixup pass drops result-redundant ones); the namespace fixup lets a carried attribute prefix shadow an inherited binding locally (matching the source document's shape) unless the element's own name relies on it; the html method minimizes boolean attributes whose value repeats their name (CHECKED="CHECKED" serializes as CHECKED); and external DTDs and entities referenced by the stylesheet or source now resolve through the transform's document loader, the same channel as document(). Four unit tests pin the new behaviors. Baseline 174 to 159 (attribset 13 to 4, copy 12 to 7).
|
||||
|
||||
|
||||
@ -125,7 +125,7 @@ flowchart TB
|
||||
|
||||
PureXML is a working, dependency-free XML library today: parse, emit, validate,
|
||||
query, and stream documents on macOS, Linux, Windows, and WASM. The test suite
|
||||
currently runs **972 tests in 166 suites** (`swift test`).
|
||||
currently runs **975 tests in 167 suites** (`swift test`).
|
||||
|
||||
### Shipped (libxml2-aligned surface)
|
||||
|
||||
|
||||
@ -202,8 +202,14 @@ extension PureXML.XPath.Compiler {
|
||||
advance()
|
||||
return .wildcard
|
||||
}
|
||||
let name = parseName()
|
||||
var name = parseName()
|
||||
guard !name.isEmpty else { throw QueryError.expectedNodeTest }
|
||||
if name.hasSuffix(":"), peek() == "*" {
|
||||
// The NCName:* form: any name in the prefix's namespace.
|
||||
advance()
|
||||
name += "*"
|
||||
return .name(name)
|
||||
}
|
||||
guard peek() == "(" else {
|
||||
return .name(name)
|
||||
}
|
||||
|
||||
@ -104,6 +104,8 @@ extension PureXML.XPath.Evaluator {
|
||||
let prefix = String(name[..<colon])
|
||||
if let uri = namespaces[prefix] {
|
||||
let local = String(name[name.index(after: colon)...])
|
||||
// The NCName:* form matches every name in the namespace.
|
||||
if local == "*" { return (qualified.namespaceURI ?? "") == uri }
|
||||
return qualified.localName == local && (qualified.namespaceURI ?? "") == uri
|
||||
}
|
||||
} else {
|
||||
@ -112,6 +114,11 @@ extension PureXML.XPath.Evaluator {
|
||||
return qualified.localName == name && (qualified.namespaceURI ?? "").isEmpty
|
||||
}
|
||||
}
|
||||
if name.hasSuffix(":*"), let colon = name.firstIndex(of: ":") {
|
||||
// Without bindings the prefix-wildcard falls back to the
|
||||
// in-document prefix string, like plain prefixed tests.
|
||||
return qualified.prefix == String(name[..<colon])
|
||||
}
|
||||
return qualified.description == name || qualified.localName == name
|
||||
}
|
||||
|
||||
|
||||
@ -11,9 +11,17 @@ struct Parts {
|
||||
var namespaceAliases: [String: PureXML.XSLT.NamespaceAlias] = [:]
|
||||
|
||||
var stylesheet: PureXML.XSLT.Stylesheet {
|
||||
PureXML.XSLT.Stylesheet(
|
||||
// Same-name globals resolve by import precedence. Imports fold in
|
||||
// precedence order (earlier imports lower, the unit's own
|
||||
// declarations appended last), so the last same-name entry wins.
|
||||
var seen = Set<String>()
|
||||
let resolvedGlobals: [PureXML.XSLT.Instruction] = globals.reversed().filter { instruction in
|
||||
guard let name = Self.globalName(instruction) else { return true }
|
||||
return seen.insert(name).inserted
|
||||
}.reversed()
|
||||
return PureXML.XSLT.Stylesheet(
|
||||
templates: templates,
|
||||
globals: globals,
|
||||
globals: resolvedGlobals,
|
||||
keys: keys,
|
||||
output: output,
|
||||
stripSpace: stripSpace,
|
||||
@ -24,19 +32,28 @@ struct Parts {
|
||||
)
|
||||
}
|
||||
|
||||
/// Folds a sub-stylesheet in: an import has lower precedence, so its globals
|
||||
/// come before and its output is overridden by this stylesheet's.
|
||||
mutating func fold(_ sub: PureXML.XSLT.Stylesheet?, isImport: Bool) {
|
||||
private static func globalName(_ instruction: PureXML.XSLT.Instruction) -> String? {
|
||||
guard case let .variable(name, _, _) = instruction else { return nil }
|
||||
return name
|
||||
}
|
||||
|
||||
/// Folds a sub-stylesheet in. Folds happen in import-precedence order
|
||||
/// (earlier imports first, the unit's own declarations absorbed last),
|
||||
/// so later contributions uniformly take precedence: globals append (the
|
||||
/// stylesheet getter keeps the last same-name entry), attribute-set
|
||||
/// definitions concatenate (later ones expand later and win), and the
|
||||
/// later output settings layer on top.
|
||||
mutating func fold(_ sub: PureXML.XSLT.Stylesheet?, isImport _: Bool) {
|
||||
guard let sub else { return }
|
||||
templates += sub.templates
|
||||
keys += sub.keys
|
||||
stripSpace.formUnion(sub.stripSpace)
|
||||
preserveSpace.formUnion(sub.preserveSpace)
|
||||
attributeSets.merge(sub.attributeSets) { mine, _ in mine }
|
||||
decimalFormats.merge(sub.decimalFormats) { mine, _ in mine }
|
||||
namespaceAliases.merge(sub.namespaceAliases) { mine, _ in mine }
|
||||
globals = isImport ? sub.globals + globals : globals + sub.globals
|
||||
output = isImport ? sub.output.merged(with: output) : output.merged(with: sub.output)
|
||||
attributeSets.merge(sub.attributeSets) { mine, theirs in mine + theirs }
|
||||
decimalFormats.merge(sub.decimalFormats) { _, theirs in theirs }
|
||||
namespaceAliases.merge(sub.namespaceAliases) { _, theirs in theirs }
|
||||
globals += sub.globals
|
||||
output = output.merged(with: sub.output)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -59,10 +59,13 @@ extension PureXML.XSLT {
|
||||
|
||||
func run() -> PureXML.Model.Node {
|
||||
var variables: [String: PureXML.XPath.Value] = [:]
|
||||
let baseContext = XSLTContext(node: root, position: 1, size: 1, variables: variables)
|
||||
for global in stylesheet.globals {
|
||||
if case let .variable(name, select, body) = global {
|
||||
variables[name] = variableValue(select, body, baseContext)
|
||||
// Each global evaluates with every previously evaluated
|
||||
// global in scope (a top-level variable may reference an
|
||||
// earlier top-level param, directly or via call-template).
|
||||
let globalContext = XSLTContext(node: root, position: 1, size: 1, variables: variables)
|
||||
variables[name] = variableValue(select, body, globalContext)
|
||||
}
|
||||
}
|
||||
let context = XSLTContext(node: root, position: 1, size: 1, variables: variables)
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
attribset/attribset27
|
||||
attribset/attribset29
|
||||
attribset/attribset44
|
||||
attribset/attribset45
|
||||
attribset/attribset46
|
||||
attribset/attribset48
|
||||
attribvaltemplate/attribvaltemplate08
|
||||
axes/axes104
|
||||
@ -18,14 +16,11 @@ axes/axes126
|
||||
axes/axes128
|
||||
boolean/boolean43
|
||||
boolean/boolean87
|
||||
conflictres/conflictres19
|
||||
conflictres/conflictres20
|
||||
conflictres/conflictres22
|
||||
conflictres/conflictres23
|
||||
conflictres/conflictres29
|
||||
conflictres/conflictres30
|
||||
conflictres/conflictres34
|
||||
conflictres/conflictres37
|
||||
copy/copy09
|
||||
copy/copy27
|
||||
copy/copy48
|
||||
@ -132,16 +127,11 @@ sort/sort33
|
||||
sort/sort34
|
||||
string/string132
|
||||
string/string143
|
||||
variable/variable29
|
||||
variable/variable31
|
||||
variable/variable32
|
||||
variable/variable33
|
||||
variable/variable34
|
||||
variable/variable35
|
||||
variable/variable41
|
||||
variable/variable55
|
||||
variable/variable67
|
||||
variable/variable70
|
||||
whitespace/whitespace06
|
||||
whitespace/whitespace07
|
||||
whitespace/whitespace13
|
||||
|
||||
157
Tests/XSLTCompositionTests.swift
Normal file
157
Tests/XSLTCompositionTests.swift
Normal file
@ -0,0 +1,157 @@
|
||||
@testable import PureXML
|
||||
import Testing
|
||||
|
||||
/// Stylesheet composition behaviors of the xalan burn-down (#130): import
|
||||
/// precedence and apply-imports scoping, relative include/import chains,
|
||||
/// global variable scope and precedence, attribute-set definition merging,
|
||||
/// xsl:copy namespace-node copying, and NCName:* name tests.
|
||||
@Suite("XSLT composition and scoping")
|
||||
struct XSLTCompositionTests {
|
||||
private let xsl = "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\""
|
||||
|
||||
@Test("apply-imports searches only the current stylesheet's own imports (5.6)")
|
||||
func test_applyImportsScope() throws {
|
||||
let leaf = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:template match="item"><leaf/></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let sibling = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:template match="item"><sibling><xsl:apply-imports/></sibling></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:import href="leaf.xsl"/>
|
||||
<xsl:import href="sibling.xsl"/>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:template match="/"><out><xsl:apply-templates select="//item"/></out></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let result = try PureXML.XSLT.transform(
|
||||
stylesheet: style,
|
||||
source: "<r><item>x</item></r>",
|
||||
documentLoader: { ["leaf.xsl": leaf, "sibling.xsl": sibling][$0] },
|
||||
)
|
||||
// sibling.xsl wins (later import); its apply-imports has no imports of
|
||||
// its own, so the built-in rule runs, not leaf.xsl's template.
|
||||
#expect(result == "<out><sibling>x</sibling></out>")
|
||||
}
|
||||
|
||||
@Test("Include and import hrefs resolve against the including stylesheet's URI")
|
||||
func test_relativeIncludeChain() throws {
|
||||
let inner = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:template match="item"><deep/></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let middle = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:include href="inner.xsl"/>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:include href="sub/middle.xsl"/>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:template match="/"><out><xsl:apply-templates select="//item"/></out></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let result = try PureXML.XSLT.transform(
|
||||
stylesheet: style,
|
||||
source: "<r><item/></r>",
|
||||
documentLoader: { ["sub/middle.xsl": middle, "sub/inner.xsl": inner][$0] },
|
||||
)
|
||||
#expect(result == "<out><deep/></out>")
|
||||
}
|
||||
|
||||
@Test("A global variable sees earlier globals, call-template included")
|
||||
func test_globalSeesEarlierGlobals() throws {
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:param name="toto" select="'titi'"/>
|
||||
<xsl:variable name="tata"><xsl:call-template name="set"/></xsl:variable>
|
||||
<xsl:template match="/"><out><xsl:value-of select="$tata"/></out></xsl:template>
|
||||
<xsl:template name="set"><xsl:value-of select="$toto"/></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
#expect(try PureXML.XSLT.transform(stylesheet: style, source: "<x/>") == "<out>titi</out>")
|
||||
}
|
||||
|
||||
@Test("Same-name globals resolve by import precedence, later sibling import winning")
|
||||
func test_globalImportPrecedence() throws {
|
||||
let first = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)><xsl:param name="v" select="'first'"/></xsl:stylesheet>
|
||||
"""
|
||||
let second = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)><xsl:param name="v" select="'second'"/></xsl:stylesheet>
|
||||
"""
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:import href="first.xsl"/>
|
||||
<xsl:import href="second.xsl"/>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:template match="/"><out><xsl:value-of select="$v"/></out></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let result = try PureXML.XSLT.transform(
|
||||
stylesheet: style,
|
||||
source: "<x/>",
|
||||
documentLoader: { ["first.xsl": first, "second.xsl": second][$0] },
|
||||
)
|
||||
#expect(result == "<out>second</out>")
|
||||
}
|
||||
|
||||
@Test("NCName:* name tests match by namespace and outrank the bare wildcard")
|
||||
func test_prefixWildcard() throws {
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl) xmlns:p="urn:p">
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:template match="/"><out><xsl:apply-templates select="//@*"/></out></xsl:template>
|
||||
<xsl:template match="@*">w,</xsl:template>
|
||||
<xsl:template match="@p:*">q,</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let source = "<r xmlns:p=\"urn:p\" a=\"1\" p:b=\"2\"/>"
|
||||
#expect(try PureXML.XSLT.transform(stylesheet: style, source: source) == "<out xmlns:p=\"urn:p\">w,q,</out>")
|
||||
}
|
||||
|
||||
@Test("Same-name attribute sets merge as ordered definitions (7.1.4)")
|
||||
func test_attributeSetMerge() throws {
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:attribute-set name="child" use-attribute-sets="alice">
|
||||
<xsl:attribute name="follow">yellowbrickroad</xsl:attribute>
|
||||
<xsl:attribute name="hole">shallow</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
<xsl:attribute-set name="child" use-attribute-sets="rabbit">
|
||||
<xsl:attribute name="follow">theleader</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
<xsl:attribute-set name="rabbit"><xsl:attribute name="hole">deep</xsl:attribute></xsl:attribute-set>
|
||||
<xsl:attribute-set name="alice"><xsl:attribute name="alice">ondrugs</xsl:attribute></xsl:attribute-set>
|
||||
<xsl:template match="/"><out xsl:use-attribute-sets="child"/></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
// The later definition expands after the earlier one (its used set
|
||||
// included), so its hole=deep and follow=theleader win.
|
||||
#expect(try PureXML.XSLT.transform(stylesheet: style, source: "<x/>")
|
||||
== "<out alice=\"ondrugs\" follow=\"theleader\" hole=\"deep\"/>")
|
||||
}
|
||||
|
||||
@Test("xsl:copy carries the source element's in-scope namespace nodes (7.5)")
|
||||
func test_copyNamespaceNodes() throws {
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:template match="inner"><xsl:copy/></xsl:template>
|
||||
<xsl:template match="/"><out><xsl:apply-templates select="//inner"/></out></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let source = "<r xmlns:a=\"urn:a\"><inner xmlns:b=\"urn:b\"/></r>"
|
||||
#expect(try PureXML.XSLT.transform(stylesheet: style, source: source)
|
||||
== "<out><inner xmlns:a=\"urn:a\" xmlns:b=\"urn:b\"/></out>")
|
||||
}
|
||||
}
|
||||
@ -123,43 +123,6 @@ struct XSLTOutputMethodTests {
|
||||
#expect(try PureXML.XSLT.transform(stylesheet: style, source: source) == "<out><f>inner c </f><p>a </p></out>")
|
||||
}
|
||||
|
||||
@Test("Same-name attribute sets merge as ordered definitions (7.1.4)")
|
||||
func test_attributeSetMerge() throws {
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:attribute-set name="child" use-attribute-sets="alice">
|
||||
<xsl:attribute name="follow">yellowbrickroad</xsl:attribute>
|
||||
<xsl:attribute name="hole">shallow</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
<xsl:attribute-set name="child" use-attribute-sets="rabbit">
|
||||
<xsl:attribute name="follow">theleader</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
<xsl:attribute-set name="rabbit"><xsl:attribute name="hole">deep</xsl:attribute></xsl:attribute-set>
|
||||
<xsl:attribute-set name="alice"><xsl:attribute name="alice">ondrugs</xsl:attribute></xsl:attribute-set>
|
||||
<xsl:template match="/"><out xsl:use-attribute-sets="child"/></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
// The later definition expands after the earlier one (its used set
|
||||
// included), so its hole=deep and follow=theleader win.
|
||||
#expect(try PureXML.XSLT.transform(stylesheet: style, source: "<x/>")
|
||||
== "<out alice=\"ondrugs\" follow=\"theleader\" hole=\"deep\"/>")
|
||||
}
|
||||
|
||||
@Test("xsl:copy carries the source element's in-scope namespace nodes (7.5)")
|
||||
func test_copyNamespaceNodes() throws {
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:template match="inner"><xsl:copy/></xsl:template>
|
||||
<xsl:template match="/"><out><xsl:apply-templates select="//inner"/></out></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let source = "<r xmlns:a=\"urn:a\"><inner xmlns:b=\"urn:b\"/></r>"
|
||||
#expect(try PureXML.XSLT.transform(stylesheet: style, source: source)
|
||||
== "<out><inner xmlns:a=\"urn:a\" xmlns:b=\"urn:b\"/></out>")
|
||||
}
|
||||
|
||||
@Test("html boolean attributes minimize when the value repeats the name")
|
||||
func test_htmlBooleanAttributes() throws {
|
||||
let style = """
|
||||
@ -172,63 +135,6 @@ struct XSLTOutputMethodTests {
|
||||
== "<Form><Input Type=\"checkbox\" CHECKED><Input Type=\"text\" Value=\"CHECKED\"></Form>")
|
||||
}
|
||||
|
||||
@Test("apply-imports searches only the current stylesheet's own imports (5.6)")
|
||||
func test_applyImportsScope() throws {
|
||||
let leaf = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:template match="item"><leaf/></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let sibling = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:template match="item"><sibling><xsl:apply-imports/></sibling></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:import href="leaf.xsl"/>
|
||||
<xsl:import href="sibling.xsl"/>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:template match="/"><out><xsl:apply-templates select="//item"/></out></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let result = try PureXML.XSLT.transform(
|
||||
stylesheet: style,
|
||||
source: "<r><item>x</item></r>",
|
||||
documentLoader: { ["leaf.xsl": leaf, "sibling.xsl": sibling][$0] },
|
||||
)
|
||||
// sibling.xsl wins (later import); its apply-imports has no imports of
|
||||
// its own, so the built-in rule runs, not leaf.xsl's template.
|
||||
#expect(result == "<out><sibling>x</sibling></out>")
|
||||
}
|
||||
|
||||
@Test("Include and import hrefs resolve against the including stylesheet's URI")
|
||||
func test_relativeIncludeChain() throws {
|
||||
let inner = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:template match="item"><deep/></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let middle = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:include href="inner.xsl"/>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let style = """
|
||||
<xsl:stylesheet version="1.0" \(xsl)>
|
||||
<xsl:include href="sub/middle.xsl"/>
|
||||
<xsl:output omit-xml-declaration="yes"/>
|
||||
<xsl:template match="/"><out><xsl:apply-templates select="//item"/></out></xsl:template>
|
||||
</xsl:stylesheet>
|
||||
"""
|
||||
let result = try PureXML.XSLT.transform(
|
||||
stylesheet: style,
|
||||
source: "<r><item/></r>",
|
||||
documentLoader: { ["sub/middle.xsl": middle, "sub/inner.xsl": inner][$0] },
|
||||
)
|
||||
#expect(result == "<out><deep/></out>")
|
||||
}
|
||||
|
||||
@Test("Stylesheet and source entities resolve through the document loader")
|
||||
func test_loaderEntityResolution() throws {
|
||||
let style = """
|
||||
|
||||
Loading…
Reference in New Issue
Block a user