Expand description
The transformation engine.
A Transform performs processing, control flow, calculations, navigation, and construction to produce a Sequence. It starts with an initial context, the most important component of which is the current Item; this is often a Node that is the source document.
All functions in the Transform operate via the Node trait. This makes the transformation engine independent of the syntax of the source, stylesheet, and result documents. Any Nodes created by the transformation use the context’s result document object.
The following transformation implements the expression “1 + 1”. The result is (hopefully) “2”.
use xrust::value::Value;
use xrust::item::{Item, Node, Sequence, SequenceTrait};
use xrust::transform::{Transform, ArithmeticOperand, ArithmeticOperator};
use xrust::transform::context::{Context, StaticContext, StaticContextBuilder};
let xform = Transform::Arithmetic(vec![
ArithmeticOperand::new(
ArithmeticOperator::Noop,
Transform::Literal(Item::<RNode>::Value(Rc::new(Value::from(1))))
),
ArithmeticOperand::new(
ArithmeticOperator::Add,
Transform::Literal(Item::<RNode>::Value(Rc::new(Value::from(1))))
)
]);
let mut static_context = StaticContextBuilder::new()
.message(|_| Ok(()))
.fetcher(|_| Ok(String::new()))
.parser(|_| Err(Error::new(ErrorKind::NotImplemented, "not implemented")))
.build();
let sequence = Context::new()
.dispatch(&mut static_context, &xform)
.expect("evaluation failed");
assert_eq!(sequence.to_string(), "2")Modules§
- callable
- Callables
- context
- Context for a transformation
- numbers
- These functions are for features defined in XPath Functions 1.0 and 2.0.
- template
- Templates
Structs§
Enums§
- Arithmetic
Operator - Axis
- Grouping
- Determine how a collection is to be divided into groups. This value would normally be inside an Option. A None value for the option means that the collection is not to be grouped.
- Kind
Test - Node
Test - Order
- The sort order
- Transform
- Specifies how a Sequence is constructed.
- Wildcard
OrName
Functions§
- in_
scope_ namespaces - A convenience function to create a namespace mapping from a Node.