Skip to main content

Stylesheet

Struct Stylesheet 

Source
pub struct Stylesheet {
    pub ast: StylesheetAst,
}
Expand description

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.

A compiled XSLT 1.0 stylesheet.

Fields§

§ast: StylesheetAst

The compiled AST — pre-parsed XPath expressions, decomposed AVTs, indexed templates. Public to ease debugging / introspection from downstream tools; the apply() machinery is the supported public surface.

Implementations§

Source§

impl Stylesheet

Source

pub fn compile(stylesheet_doc: &Document) -> Result<Stylesheet, XsltError>

Compile a parsed stylesheet document into a reusable transformer. Walks the stylesheet once, pre-parses every XPath expression in select/match/test/use attributes, decomposes Attribute Value Templates, and indexes templates for later pattern-matching.

The supplied document MUST have been parsed in namespace-aware mode (ParseOptions { namespace_aware: true, .. }) — XSLT is fundamentally namespace-driven and the compiler detects xsl:* instructions via their namespace URI. Use Stylesheet::compile_str for the common case where you have the stylesheet source as text and want the parse handled for you.

Source

pub fn compile_str(stylesheet_text: &str) -> Result<Stylesheet, XsltError>

Parse + compile a stylesheet from source text. Convenience wrapper that sets namespace_aware: true for you.

Stylesheets that use xsl:import / xsl:include will successfully compile, but the imports’ templates won’t be loaded — references to imported templates surface as runtime errors. For stylesheets that need import resolution, use Stylesheet::compile_str_with_loader.

Source

pub fn compile_str_with_loader( stylesheet_text: &str, loader: &dyn Loader, base: Option<&str>, ) -> Result<Stylesheet, XsltError>

Parse + compile + resolve imports. Each xsl:import / xsl:include is followed via loader, recursively, with base supplying the URI to resolve relative hrefs against.

Imported templates are merged into the resulting AST with lower [Template::import_precedence] than the importing stylesheet’s own templates, so XSLT 1.0 §2.6.2 import precedence is honoured at pattern-match time.

Source

pub fn compile_str_with_packages( stylesheet_text: &str, loader: &dyn Loader, base: Option<&str>, packages: HashMap<String, (String, Option<String>)>, ) -> Result<Stylesheet, XsltError>

Compile with a package library available for xsl:use-package (XSLT 3.0 §3.5.1) — packages maps a package name to its (source text, base URI). Imports/includes still resolve via loader.

Source

pub fn apply(&self, source_doc: &Document) -> Result<ResultTree, XsltError>

Apply this stylesheet to source_doc, returning the materialized result tree. Serialize via ResultTree::to_string (honors <xsl:output method=…>) or inspect ResultTree::children directly.

Source

pub fn apply_with_loader( &self, source_doc: &Document, loader: &dyn Loader, base: Option<&str>, ) -> Result<ResultTree, XsltError>

Apply this stylesheet using loader to resolve any document() URIs the stylesheet references with string literals. base supplies the base URI for relative-href resolution (passed through to Loader::load).

Dynamic forms of document() — node-set arguments, the empty-string URI, or any expression that isn’t a string literal — return a clear runtime error explaining the limitation. Stylesheets that don’t call document() at all behave identically to Stylesheet::apply.

Source

pub fn apply_with_extensions( &self, source_doc: &Document, extensions: &dyn ExtensionFunctions, ) -> Result<ResultTree, XsltError>

Apply this stylesheet with caller-supplied XPath extension functions registered via ExtensionFunctions.

Extension calls are dispatched via namespace + local name: when an XPath expression invokes prefix:fname(…), the engine looks up (namespace-uri(prefix), "fname") in the supplied trait object. Returning Some(Ok(_)) provides the result; Some(Err(_)) surfaces a runtime error; None falls through to the built-in EXSLT chain and finally to “unknown function”.

The most common use case is implemented by Extensions, which lets callers register individual closures keyed by (namespace, name). For richer integrations (stateful dispatch, integration with an existing function registry, etc.) implement ExtensionFunctions on your own type.

Source

pub fn apply_with_loader_and_extensions( &self, source_doc: &Document, loader: &dyn Loader, base: Option<&str>, extensions: &dyn ExtensionFunctions, ) -> Result<ResultTree, XsltError>

Apply this stylesheet with both a document() loader and caller-supplied XPath extension functions. Combines Stylesheet::apply_with_loader and Stylesheet::apply_with_extensions.

Source

pub fn apply_with_params( &self, source_doc: &Document, loader: &dyn Loader, base: Option<&str>, params: &[(String, String)], ) -> Result<ResultTree, XsltError>

Apply the stylesheet with caller-supplied overrides for top-level xsl:param declarations. Each (name, value) pair replaces the matching param’s default at apply time — XSLT 1.0 §11.4. Match is by local-name; unmatched names are silently ignored.

Source

pub fn apply_with_params_and_initial( &self, source_doc: &Document, loader: &dyn Loader, base: Option<&str>, params: &[(String, String)], initial_template: Option<&str>, ) -> Result<ResultTree, XsltError>

Apply with both top-level params and a named-template entry point. initial_template selects an xsl:template name="…" declaration to call instead of doing the default apply-templates dispatch on the document root. This matches the XSLT 3.0 named-entry convention used by W3C test harnesses via <initial-template name="go"/>.

Source

pub fn apply_with_params_initial_and_mode( &self, source_doc: &Document, loader: &dyn Loader, base: Option<&str>, params: &[(String, String)], initial_template: Option<&str>, initial_mode: Option<&str>, ) -> Result<ResultTree, XsltError>

Apply with top-level params, an optional named-template entry point, and an optional initial mode for the default apply-templates dispatch. XSLT 3.0 / W3C test conventions pass <initial-mode name="X"/> so the entry-point dispatch sees the named mode rather than the unnamed default.

Trait Implementations§

Source§

impl Debug for Stylesheet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.