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

PipelineExpression

A pipeline XPath expression

UnaryExpression

A unary XPath expression. Practially, this means -foo.

BinaryExpression

Any binary XPath expression. a/b; a and b; a | b.

PredicatedExpression

A filtered XPath expression. $var[1]; (a or b)[foo][@bar].

AbsolutePath

An absolute XPath path. /a/b/c; //a/ancestor:b/@c.

Step

A single step in a relative path. a; @b; text(); parent::foo:bar[5].

NameTest

An element name node test for a Step.

NodeType

A node type node test for a Step.

AbbreviatedStep

An abbreviated XPath step. . or ..

VariableReference

An XPath variable reference. $foo; $myns:foo.

FunctionCall

An XPath function call. foo(); my:foo(1); foo(1, 'a', $var).

class kodexa.selectors.ast.PipelineExpression(left, op, right)

Bases: object

A 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: object

A 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: object

Any 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: object

A 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: object

An 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: object

A 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: object

An 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: object

A 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: object

An abbreviated XPath step. . or ..

abbr

the abbreviated step

resolve(content_node, variables, context: SelectorContext)
class kodexa.selectors.ast.VariableReference(name)

Bases: object

An 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: object

An 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)