Something went wrong. Try again.
An XSLT 1.0 processor for Zig 0.16, built on zxml.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! What this engine can fail at, and the evaluator instantiated to know it.//!//! zxpath is generic over the error set of whatever supplies its variables and//! extension functions, precisely so that XPath's own set stays six errors//! long. This is the other end of that: the things an *XSLT* engine can go//! wrong at, gathered in one place because the pattern matcher, the stylesheet//! reader and the transformer all need to name the same instantiation.
const std = @import("std");const ztree = @import("ztree");const zxpath = @import("zxpath");
/// The failures that belong to XSLT rather than to XPath.pub const Host = error{ /// `key()` named a key the stylesheet does not declare. UnknownKey, /// `document()` could not read what it was pointed at. DocumentNotFound, /// `xsl:message terminate="yes"`. Terminated, /// The stylesheet is not valid XSLT. `Stylesheet.diagnostic` says how. InvalidStylesheet, /// The transformation ran past `Options.step_limit`. /// /// Not a clock: a limit measured in seconds means something different on /// every machine, and the run that passes on the fast one is not a test. /// A count of instructions instantiated is the same number everywhere, /// which is the same argument the fuzzer's `--iterations` makes. StepLimitExceeded, /// `exsl:document` had nowhere to put a secondary result document: the /// caller supplied no `Sink`, or the one it supplied refused this `href`. /// Refusing is the default, because a stylesheet that can write anywhere /// it likes is a stylesheet that can write anywhere it likes. DocumentNotWritten, // Loading a document with `document()` parses it, so a parse failure is // something this engine can surface.} || ztree.ParseError;
/// The evaluator this engine runs expressions on.pub const Evaluator = zxpath.Evaluator(Host);
/// Everything a transformation can fail with: XPath's errors and XSLT's.pub const Error = Evaluator.Error;
/// How every document an XSLT processor reads is parsed.////// The internal subset matters to a transformation: the general entities it/// declares have to resolve before a template can match anything, and the/// attribute defaults it gives are attribute nodes as far as XPath is/// concerned even though no start tag wrote them. libxslt reads it, so a/// stylesheet written against libxslt assumes it was read.////// It lives here rather than at each call site because there are four of them/// -- the command-line tool, `xsl:include` and `xsl:import`, `document()`, and/// the corpus runner -- and a document parsed by different rules from the one/// beside it is a difference nothing would notice until an output was wrong.pub const parse_options: ztree.ParseOptions = .{ .dtd = true };
/// Parses a document the way the engine needs it.pub fn parse(gpa: std.mem.Allocator, src: []const u8, base_uri: []const u8) ztree.ParseError!*ztree.Document { var options = parse_options; options.base_uri = base_uri; return ztree.parse(gpa, src, options);}