feat(xpath): following and preceding axes from attribute nodes

The following and preceding axes work from attribute and namespace
starts, anchored at the owner element per XPath 1.0 document order:
an attribute follows its element, precedes the element's children,
and has no descendants of its own. Xalan baseline 182 -> 174
(axes 16 -> 8).
This commit is contained in:
Mihaela Mihaljevic 2026-06-10 14:05:28 +02:00
parent 7b4887b7ad
commit a86a57eec4
3 changed files with 12 additions and 12 deletions

View File

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Following/preceding from attribute nodes, twelfth xalan burn-down (#130): the following and preceding axes now work from attribute and namespace starts, anchored at the owner element per the XPath 1.0 document order (an attribute follows its element and precedes its children, and has no descendants of its own). Baseline 182 to 174 (axes 16 to 8).
- Keys per document, in document order, eleventh xalan burn-down (#130): `key()` resolves its index against the current node's own document (built lazily per document root, so keys work inside document() trees), a node-set `use` expression indexes the matched node under every member's string value, and key() results return in document order regardless of the lookup value order. Baseline 187 to 182.
- Sort keys in context and cross-document template matching, tenth xalan burn-down (#130): xsl:sort keys are computed once per node with the node's own evaluation context (its position and size in the selection, the caller's variables, functions, and namespace bindings), so position()-based and variable-referencing keys work, and NaN keys order before every number under data-type="number" (the Xalan order); match patterns evaluate over the matched node's own document rather than the transform source, so templates match nodes loaded through document() (the match cache keys include the document identity). Baseline 204 to 187 (sort 18 to 11, mdocs 14 to 6).
- Prolog and CDATA conformance, ninth xalan burn-down (#130): the XML declaration precedes the document type declaration; a public-only doctype is emitted by the html method (16.2) and ignored by the xml method, which requires `doctype-system` (16.1); the simplified stylesheet syntax of 2.3 (a literal result element carrying `xsl:version`) compiles as a single match="/" template; and cdata-section-elements text containing "]]>" splits across section boundaries so no section holds the terminator. Baseline 218 to 204 (output 34 to 20).

View File

@ -73,14 +73,21 @@ extension PureXML.XPath {
private static func following(of node: Node) -> [Node] {
let all = documentNodes(of: node)
guard let index = all.firstIndex(of: node) else { return [] }
let excluded = Set(descendants(of: node))
return all[(index + 1)...].filter { !excluded.contains($0) }
if let index = all.firstIndex(of: node) {
let excluded = Set(descendants(of: node))
return all[(index + 1)...].filter { !excluded.contains($0) }
}
// An attribute or namespace start: document order places it after
// its owner and before the owner's children, and it has no
// descendants, so everything after the owner follows.
guard let owner = node.parent, let index = all.firstIndex(of: owner) else { return [] }
return Array(all[(index + 1)...])
}
private static func preceding(of node: Node) -> [Node] {
let all = documentNodes(of: node)
guard let index = all.firstIndex(of: node) else { return [] }
let anchorIndex = all.firstIndex(of: node) ?? node.parent.flatMap { all.firstIndex(of: $0) }
guard let index = anchorIndex else { return [] }
let excluded = Set(ancestors(of: node))
return all[..<index].filter { !excluded.contains($0) }.reversed()
}

View File

@ -15,22 +15,14 @@ attribset/attribset45
attribset/attribset46
attribset/attribset48
attribvaltemplate/attribvaltemplate08
axes/axes103
axes/axes104
axes/axes105
axes/axes106
axes/axes107
axes/axes108
axes/axes109
axes/axes110
axes/axes111
axes/axes112
axes/axes116
axes/axes124
axes/axes126
axes/axes128
axes/axes88
axes/axes89
boolean/boolean43
boolean/boolean87
conflictres/conflictres19