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: StylesheetAstThe 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
impl Stylesheet
Sourcepub fn compile(stylesheet_doc: &Document) -> Result<Stylesheet, XsltError>
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.
Sourcepub fn compile_str(stylesheet_text: &str) -> Result<Stylesheet, XsltError>
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.
Sourcepub fn compile_str_with_loader(
stylesheet_text: &str,
loader: &dyn Loader,
base: Option<&str>,
) -> Result<Stylesheet, XsltError>
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.
Sourcepub fn compile_str_with_packages(
stylesheet_text: &str,
loader: &dyn Loader,
base: Option<&str>,
packages: HashMap<String, (String, Option<String>)>,
) -> Result<Stylesheet, XsltError>
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.
Sourcepub fn apply(&self, source_doc: &Document) -> Result<ResultTree, XsltError>
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.
Sourcepub fn apply_with_loader(
&self,
source_doc: &Document,
loader: &dyn Loader,
base: Option<&str>,
) -> Result<ResultTree, XsltError>
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.
Sourcepub fn apply_with_extensions(
&self,
source_doc: &Document,
extensions: &dyn ExtensionFunctions,
) -> Result<ResultTree, XsltError>
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.
Sourcepub fn apply_with_loader_and_extensions(
&self,
source_doc: &Document,
loader: &dyn Loader,
base: Option<&str>,
extensions: &dyn ExtensionFunctions,
) -> Result<ResultTree, XsltError>
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.
Sourcepub fn apply_with_params(
&self,
source_doc: &Document,
loader: &dyn Loader,
base: Option<&str>,
params: &[(String, String)],
) -> Result<ResultTree, XsltError>
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.
Sourcepub 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>
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"/>.
Sourcepub 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>
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.