import Testing
@testable import PureXML
/// `xsl:call-template` selects its target by import precedence (XSLT 1.0
/// section 6), not by the position of the definition in the flattened
/// stylesheet. An included template carries the including unit's precedence,
/// so it outranks a same-name template from an import (Apache Xalan
/// namedtemplate17-19, namespace13).
@Suite("XSLT call-template precedence")
struct XSLTCallTemplatePrecedenceTests {
private let xsl = "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\""
@Test("An include outranks a same-name import")
func test_includeOutranksImport() throws {
let imported = """
IMPORT
"""
let included = """
INCLUDE
"""
let style = """
"""
let result = try PureXML.XSLT.transform(
stylesheet: style,
source: "",
documentLoader: { ["imp.xsl": imported, "inc.xsl": included][$0] },
)
// The included template (the including unit's precedence) wins over the
// imported one, which folds in first by position.
#expect(result == "INCLUDE")
}
}