1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Node model and evaluator of the XPath 2.0 subset that the official e-invoicing
//! validation stylesheets use, with the behaviour of the reference engine, Saxon-HE
//! 12.10.
//!
//! * [`tree`]: immutable XML trees ([`Document`], [`Node`]), parsed from text with every
//! whitespace text node kept, or built with a [`TreeBuilder`].
//! * [`compile`]: an expression parsed by [`einvoice_xpath`] is resolved against a
//! [`StaticContext`] (variables, host functions, whether the XSLT functions exist) into
//! a [`CompiledExpr`]. Unknown functions and variables are errors here, not at
//! evaluation. The static types Saxon infers are inferred too, where they change a
//! result: `xs:decimal` of an argument statically typed `xs:integer` strips its
//! trailing zeros, as Saxon-HE 12.10's up-casting converter does, and returns one
//! statically typed `xs:decimal` unchanged (Saxon removes the cast); `div` of operands
//! statically typed `xs:decimal` (or one `xs:integer`) is Saxon's decimal division. The
//! host gives the static types of its variables and functions as [`ValueType`]s, which
//! infer them as Saxon does in a stylesheet from a `select` expression and an `as`
//! type.
//! * [`CompiledExpr::evaluate`] and [`CompiledExpr::effective_boolean_value`] evaluate it
//! in a [`DynamicContext`] (the [`Host`] and the [`Clock`]: the implicit timezone and
//! the current date and time, given by the caller, so that the evaluator reads no clock,
//! which `wasm32-unknown-unknown` does not have) with a [`Context`] (focus and current
//! item). Atomic values and their operations are those of [`einvoice_xdm`].
//!
//! Sequences are evaluated lazily, so that consumers that stop early (effective boolean
//! values, `exists`, general comparisons, `some`/`every`, `[1]`) raise only the errors
//! of the items they read, as Saxon does.
//!
//! Functions: `not`, `true`, `false`, `boolean`, `count`, `sum`, `normalize-space`,
//! `string-length`, `string`, `number`, `contains`, `starts-with`, `ends-with`,
//! `substring`, `substring-before`, `substring-after`, `concat`, `translate`,
//! `upper-case`, `round`, `abs`, `name`, `local-name`, `namespace-uri`, `last`,
//! `position`, `exists`, `document-uri` (also with no argument, as in XPath 3.0), `root`,
//! `base-uri`, `matches`, `replace`, `tokenize`, `string-to-codepoints`,
//! `codepoints-to-string`, `string-join`, `reverse`, `current-dateTime`,
//! `distinct-values`, the constructors `xs:decimal`, `xs:date`, `xs:integer`,
//! `xs:string`, and in XSLT `current`, `document` and `system-property` (the last two
//! through the [`Host`]).
//!
//! ```
//! use einvoice_xpath::{NamespaceMap, XS_NAMESPACE, parse_expr};
//! use einvoice_xpath_eval::{Clock, Context, Document, DynamicContext, Item, NoHost, SimpleStaticContext, compile};
//!
//! let doc = Document::parse("<i><l a='19.99'/><l a='0.01'/></i>", None)?;
//! let ns = NamespaceMap::new().bind("xs", XS_NAMESPACE);
//! let expr = compile(&parse_expr("sum(//l/xs:decimal(@a))", &ns)?, &SimpleStaticContext::new())?;
//! // UTC, and the current date and time read by the host: 2026-09-10T00:26:40Z.
//! let dc = DynamicContext::new(&NoHost, Clock::from_unix_millis(0, 1_789_000_000_000)?);
//! let result = expr.evaluate(&dc, &Context::for_item(Item::Node(doc.root())))?;
//! assert_eq!(result[0].string_value(), "20");
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use Item;
pub use ;
pub use ;