Only the static deduplicated helper moves to XSLTElements.swift (it needs no private types); attributeSetAttributes stays in the transformer so the evaluation context and result-item types remain file-private, satisfying the one-file-scope-type namespacing gate.
18 lines
732 B
Swift
18 lines
732 B
Swift
extension PureXML.XSLT.Transformer {
|
|
/// The attributes with duplicates by name removed, keeping the last (so a
|
|
/// later attribute overrides one from an attribute set or an earlier source).
|
|
static func deduplicated(_ attributes: [PureXML.Model.Attribute]) -> [PureXML.Model.Attribute] {
|
|
var indexByName: [String: Int] = [:]
|
|
var result: [PureXML.Model.Attribute] = []
|
|
for attribute in attributes {
|
|
if let index = indexByName[attribute.name.description] {
|
|
result[index] = attribute
|
|
} else {
|
|
indexByName[attribute.name.description] = result.count
|
|
result.append(attribute)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
}
|