kodexa.selectors.ast
Abstract Syntax Tree nodes for parsed XPath.
This module contains basic nodes for representing parsed XPath expressions. The parser provided by this module creates its parsed XPath representation from the classes defined in this module. Library callers will mostly not use this module directly, unless they need to produce XPath ASTs from scratch or perhaps introspect ASTs returned by the parser.
This code was derived from https://github.com/emory-libraries/eulxml
Module Contents
Classes
A pipeline XPath expression |
|
A unary XPath expression. Practially, this means -foo. |
|
Any binary XPath expression. a/b; a and b; a | b. |
|
A filtered XPath expression. $var[1]; (a or b)[foo][@bar]. |
|
An absolute XPath path. /a/b/c; //a/ancestor:b/@c. |
|
A single step in a relative path. a; @b; text(); parent::foo:bar[5]. |
|
An element name node test for a Step. |
|
A node type node test for a Step. |
|
An abbreviated XPath step. . or .. |
|
An XPath variable reference. $foo; $myns:foo. |
|
An XPath function call. foo(); my:foo(1); foo(1, 'a', $var). |
- class kodexa.selectors.ast.PipelineExpression(left, op, right)
Bases:
objectA pipeline XPath expression
- left
the left side of the pipeline expression
- op
the operator of the pipeline expression
- right
the right side of the pipeline expression
- resolve(content_node: kodexa.ContentNode, variables, context: SelectorContext)
- class kodexa.selectors.ast.UnaryExpression(op, right)
Bases:
objectA unary XPath expression. Practially, this means -foo.
- op
the operator used in the expression
- right
the expression the operator is applied to
- class kodexa.selectors.ast.BinaryExpression(left, op, right)
Bases:
objectAny binary XPath expression. a/b; a and b; a | b.
- left
the left side of the binary expression
- op
the operator of the binary expression
- right
the right side of the binary expression
- resolve(content_node: kodexa.ContentNode, variables, context: SelectorContext)
- get_value(side, content_node, variables, context: SelectorContext)
- class kodexa.selectors.ast.PredicatedExpression(base, predicates=None)
Bases:
objectA filtered XPath expression. $var[1]; (a or b)[foo][@bar].
- base
the base expression to be filtered
- predicates
a list of filter predicates
- append_predicate(pred)
- resolve(content_node, variables, context: SelectorContext)
- class kodexa.selectors.ast.AbsolutePath(op='/', relative=None)
Bases:
objectAn absolute XPath path. /a/b/c; //a/ancestor:b/@c.
- op
the operator used to root the expression
- relative
the relative path after the absolute root operator
- resolve(content_node, variables, context: SelectorContext)
- class kodexa.selectors.ast.Step(axis, node_test, predicates)
Bases:
objectA single step in a relative path. a; @b; text(); parent::foo:bar[5].
- axis
the step’s axis, or @ or None if abbreviated or undefined
- node_test
a NameTest or NodeType object describing the test represented
- predicates
a list of predicates filtering the step
- resolve(obj, variables, context: SelectorContext)
- class kodexa.selectors.ast.NameTest(prefix, name)
Bases:
objectAn element name node test for a Step.
- prefix
the namespace prefix used for the test, or None if unset
- name
the node name used for the test, or *
- test(obj, variables, context: SelectorContext)
- class kodexa.selectors.ast.NodeType(name, literal=None)
Bases:
objectA node type node test for a Step.
- name
the node type name, such as node or text
- literal
the argument to the node specifier. XPath allows these only for processing-instruction() node tests.
- class kodexa.selectors.ast.AbbreviatedStep(abbr)
Bases:
objectAn abbreviated XPath step. . or ..
- abbr
the abbreviated step
- resolve(content_node, variables, context: SelectorContext)
- class kodexa.selectors.ast.VariableReference(name)
Bases:
objectAn XPath variable reference. $foo; $myns:foo.
- name
a tuple (prefix, localname) containing the variable name
- resolve(variables, context: SelectorContext)
- class kodexa.selectors.ast.FunctionCall(prefix, name, args)
Bases:
objectAn XPath function call. foo(); my:foo(1); foo(1, ‘a’, $var).
- prefix
the namespace prefix, or None if unspecified
- name
the local function name
- args
a list of argument expressions
- resolve(content_node, variables, context: SelectorContext)