Skip to main content

Crate sup_xml_xslt

Crate sup_xml_xslt 

Source
Expand description

XSLT 1.0 transformation engine.

Public API surface:

use sup_xml_xslt::Stylesheet;
use sup_xml_core::{parse_str, ParseOptions};

let xslt = Stylesheet::compile_str(r#"<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:template match="/"><out><xsl:value-of select="/r"/></out></xsl:template>
</xsl:stylesheet>"#).unwrap();

let src = parse_str("<r>hello</r>", &ParseOptions::default()).unwrap();
let result = xslt.apply(&src).unwrap();
assert_eq!(result.to_string().unwrap(), "<out>hello</out>");

The engine is built on top of sup-xml-core’s XPath evaluator — XSLT match patterns and select= expressions parse to the same AST, and template-body XPath calls reach the engine’s binding hook for the XSLT-added functions (current(), document(), key(), format-number() etc.). EXSLT functions (math/date/str/set) are already always-on in the XPath engine, so XSLT stylesheets that use them work without any additional registration step.

Re-exports§

pub use loader::FilesystemLoader;
pub use loader::InMemoryLoader;
pub use loader::Loader;
pub use loader::NullLoader;
pub use ast::StylesheetAst;
pub use error::XsltError;
pub use extensions::ExtensionFunctions;
pub use extensions::Extensions;
pub use result_tree::ResultTree;

Modules§

ast
Compiled XSLT AST — the output of crate::compiler and the input to the crate::eval instruction evaluator.
compiler
Stylesheet compiler — walks a parsed XSLT document and produces a StylesheetAst.
error
XsltError — single error type covering compile + apply + serialise.
eval
XSLT instruction evaluator.
extensions
User-supplied extension functions for XSLT / XPath.
format_number
format-number(number, picture, decimal-format?) — XSLT 1.0 §12.3.
functions
XSLT-added XPath functions — XSLT 1.0 §12.
loader
Stylesheet / document loader — pluggable resolver used by xsl:import, xsl:include, and the document() XPath function.
number
xsl:number — generate sequence numbers (XSLT 1.0 §7.7).
output
Output serialisers — turn a ResultTree into bytes per xsl:output’s method (XML / HTML / text).
pattern
XSLT pattern matching — XSLT 1.0 §5.2.
result_tree
Lightweight intermediate result-tree representation.
schematron
ISO Schematron validator — native implementation.
sort
xsl:sort engine — sort a node sequence by N keys before xsl:apply-templates / xsl:for-each iterates it.
walk
AST walkers — visit every XPath Expr inside a compiled stylesheet.
whitespace
Source-tree whitespace handling — implements xsl:strip-space / xsl:preserve-space (XSLT 1.0 §3.4).

Structs§

Stylesheet
A compiled XSLT 1.0 stylesheet, ready to apply to source documents. Compilation walks the stylesheet tree once, pre-parses every XPath expression, and resolves xsl:import/xsl:include chains.

Enums§

XPathValue
The XPath value type passed to extension functions and returned by them. Re-exported from sup-xml-core for convenience.

Constants§

XSLT_NS
The XSLT namespace URI — all xsl:* instructions are recognised by belonging to this URI.