@testable import PureXML
import Testing
@Suite("XSLT xsl:apply-imports")
struct XSLTApplyImportsTests {
private let xsl = "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\""
private func transform(_ stylesheet: String, _ source: String, loader: @escaping (String) -> String?) throws -> String {
try PureXML.XSLT.transform(stylesheet: stylesheet, source: source, documentLoader: loader)
}
@Test("apply-imports invokes the lower-precedence imported template")
func test_applyImports() throws {
let base = """
[base:]
"""
let main = """
main()
"""
let output = try transform(main, "- x
") { $0 == "base.xsl" ? base : nil }
#expect(output == "main([base:x])")
}
@Test("apply-imports with no lower-precedence match falls back to the built-in rule")
func test_applyImportsBuiltIn() throws {
let base = """
never
"""
let main = """
main[]
"""
// No imported template matches "item", so apply-imports uses the built-in
// rule, which outputs the element's text value.
let output = try transform(main, "- y
") { $0 == "base.xsl" ? base : nil }
#expect(output == "main[y]")
}
}