pyxsd.xpath

XPath evaluation substrate for the pyxsd transformation engine.

The package contains the diagnostic capability probes, the continuation seam, and the standalone, schema-aware expression environment. It does not import stylesheet execution code: expressions compile and evaluate without a transformation, initial template, result builder, or mode.

Classes

CompiledExpression

An immutable expression compiled against one static context.

XPathEngine

Compile and evaluate standalone XPath expressions.

XPathStaticContext

Immutable parser configuration shared by compiled expressions.

ExpressionEnvironment

One invocation's dynamic XPath values.

Focus

An explicit XPath focus with the absent/empty distinction preserved.

Package Contents

class pyxsd.xpath.CompiledExpression

An immutable expression compiled against one static context.

source: str
static_context: pyxsd.xpath.environment.XPathStaticContext
version: str
continuation_plan: pyxsd.xpath.continuation.CompiledExpression | None = None
variable_names: frozenset[str]
free_variable_names: frozenset[str]
class pyxsd.xpath.XPathEngine(version='3.1', *, xslt_functions=True)

Compile and evaluate standalone XPath expressions.

Parameters:
  • version (str)

  • xslt_functions (bool)

property version: str
Return type:

str

property xslt_functions: bool

Whether XSLT-only functions such as key are registered.

Return type:

bool

property parser_class: type[Any]
Return type:

type[Any]

compile(source, static_context=None)

Parse source and freeze every static decision it depends on.

Parameters:
  • source (str)

  • static_context (pyxsd.xpath.environment.XPathStaticContext | None)

Return type:

CompiledExpression

evaluate(compiled, environment, *, focus=None)

Evaluate one compiled expression with invocation-local dynamic state.

When environment.parser_cache is supplied, the parser and its symbol table are reused across evaluations of the same static configuration; every dynamic-context component still comes from environment.

Parameters:
Return type:

pyxsd.xdm.XdmSequence

class pyxsd.xpath.XPathStaticContext

Immutable parser configuration shared by compiled expressions.

functions declares host functions that the parser may resolve at compile time. Keys are prefixed lexical QNames ("m:f") or Clark names whose namespace has a prefix in namespaces. The declaration carries arity only; the callable is supplied by each ExpressionEnvironment.

namespaces: collections.abc.Mapping[str, str]
default_namespace: str | None = None
variable_types: collections.abc.Mapping[str, str]
functions: collections.abc.Mapping[str, FunctionArity]
schema: pyxsd.xdm.schema.SchemaPool | None = None
base_uri: str | None = None
default_collation: str | None = None
xsd_version: str | None = None
xslt_version: str | None = None
compatibility_mode: bool = False
function_arity(name)

Return the declared arity for name, trying Clark/prefix forms.

Parameters:

name (str)

Return type:

FunctionArity | None

expand_name(name)

Expand a prefixed lexical QName with this context’s namespaces.

Parameters:

name (str)

Return type:

str | None

lexical_name(name)

Return a prefixed lexical form for a Clark name, if a prefix exists.

Parameters:

name (str)

Return type:

str | None

class pyxsd.xpath.ExpressionEnvironment

One invocation’s dynamic XPath values.

Construction copies every mapping. current_datetime and the implicit timezone are fixed here, so repeated evaluations through the same environment observe stable dynamic values. Resources are exactly the explicitly supplied documents/collections/text resources; absence is a resource denial, never a silent filesystem or network read.

variables: collections.abc.Mapping[str, Any]
functions: collections.abc.Mapping[str, Any]
function_overrides: collections.abc.Mapping[str, Any]
key_indexes: collections.abc.Mapping[str, collections.abc.Mapping[Any, collections.abc.Sequence[pyxsd.xdm.nodes.XdmNode]]]
documents: collections.abc.Mapping[str, pyxsd.xdm.nodes.XdmDocument]
collections: collections.abc.Mapping[str, collections.abc.Sequence[pyxsd.xdm.nodes.XdmNode]]
default_collection: collections.abc.Sequence[pyxsd.xdm.nodes.XdmNode] = ()
text_resources: collections.abc.Mapping[str, str]
decimal_formats: collections.abc.Mapping[str | None, collections.abc.Mapping[str, str]]
current_datetime: datetime.datetime | None = None
implicit_timezone: elementpath.datatypes.datetime.Timezone | str | datetime.tzinfo | datetime.timedelta | None = None
base_uri: str | None = None
parser_cache: object | None = None
adapter_registry: object | None = None
key_lookup: collections.abc.Callable[[pyxsd.xdm.values.XdmItem | None, tuple[pyxsd.xdm.values.XdmSequence, ...]], pyxsd.xdm.values.XdmSequence] | None = None
id_lookup: collections.abc.Callable[[pyxsd.xdm.values.XdmItem | None, tuple[pyxsd.xdm.values.XdmSequence, ...], bool], pyxsd.xdm.values.XdmSequence] | None = None
idref_lookup: collections.abc.Callable[[pyxsd.xdm.values.XdmItem | None, tuple[pyxsd.xdm.values.XdmSequence, ...]], pyxsd.xdm.values.XdmSequence] | None = None
property current_date_time: datetime.datetime

Alias matching the XPath function’s spelling.

Return type:

datetime.datetime

property timezone: elementpath.datatypes.datetime.Timezone

The normalized implicit timezone.

Return type:

elementpath.datatypes.datetime.Timezone

class pyxsd.xpath.Focus

An explicit XPath focus with the absent/empty distinction preserved.

Focus.absent() means no context item exists; an expression that needs one raises XPDY0002. Focus.empty() is an explicitly empty focus and evaluates to the empty sequence without entering the expression. The two are never converted into one another.

kind: FocusKind
item: pyxsd.xdm.values.XdmItem | None = None
position: int = 1
size: int = 1
classmethod absent()
Return type:

Focus

classmethod empty()
Return type:

Focus

classmethod singleton(item, *, position=1, size=1)
Parameters:
Return type:

Focus

property is_absent: bool
Return type:

bool

property is_empty: bool
Return type:

bool