engine

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 3 Imported by: 2 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine runs XSLT 3.0 transformations, XPath 3.1 expressions and XSD 1.0/1.1 validation in pure Go: Transform and TransformTo run a stylesheet, Compile prepares one for many runs, EvalXPath evaluates an expression and Validate checks a document against schemas. Every entry point reports problems as Diagnostics instead of panicking, and has a Context variant for cancellation.

Index

Constants

View Source
const (
	SeverityError   = engine.SeverityError
	SeverityWarning = engine.SeverityWarning
)

Severities of a Diagnostic.

View Source
const (
	XSD10 = engine.XSD10
	XSD11 = engine.XSD11
)

XSD versions for ValidateRequest.

Variables

This section is empty.

Functions

func Compile added in v0.0.8

func Compile(req Request) (*Stylesheet, []Diagnostic)

Compile compiles req.Stylesheet (imports and includes resolved against req.BaseDir) without running it, so the same stylesheet can then be run many times against changing data — Stylesheet.Transform, TransformTo and TransformFromReader. A *Stylesheet is immutable and safe for concurrent use. Source, Params and InitialTemplate of req are ignored; they belong to each run (TransformRequest). On failure the Stylesheet is nil and the diagnostics carry the error with its line and column in the stylesheet. It never panics.

Types

type Diagnostic

type Diagnostic = engine.Diagnostic

Diagnostic is an error or warning, with its W3C error code and, where known, the line and column it refers to.

type Features added in v0.2.0

type Features = engine.Features

Features turns on optional XSLT 3.0 capabilities (schema awareness, XSLT 1.0 backwards compatibility, strict streaming) per stylesheet.

type Limits added in v0.3.0

type Limits = engine.Limits

Limits bounds what a run may execute (instruction steps, nesting depth).

type Request

type Request = engine.Request

Request is one transformation: the stylesheet, the source document, parameters, the initial template/mode, and the security, limit and feature settings.

type Result

type Result = engine.Result

Result is the outcome of a transformation: the principal output, the documents written by xsl:result-document, messages and Diagnostics.

func Transform

func Transform(req Request) Result

Transform runs req and returns the result. It never panics; errors are reported as Diagnostics on the Result.

func TransformContext added in v0.3.0

func TransformContext(ctx context.Context, req Request) Result

TransformContext is Transform that stops when ctx is done — a deadline, a cancelled request. The run then ends with an error diagnostic that names ctx.Err(). Cancellation is checked every 1024 instructions and inside long XPath evaluations, so a run stops shortly after ctx is done.

func TransformFromReader added in v0.0.5

func TransformFromReader(src io.Reader, req Request) Result

TransformFromReader is Transform with the source document read from src instead of req.Source (ignored), avoiding the extra copy a caller would otherwise pay converting their own io.Reader into a string before calling Transform. It never panics; errors (including a read failure on src) are reported as Diagnostics.

func TransformTo

func TransformTo(w io.Writer, req Request) Result

TransformTo runs req and writes the principal result to w rather than returning it in Result.Output, which stays empty; every other field is populated exactly as Transform populates it. A result large enough to matter never exists as one string, and when the stylesheet allows it the result tree is serialized and released while it is built — so a transformation that streams a large xsl:source-document through to its output runs in bounded memory on both sides. It never panics; errors are reported as Diagnostics.

func TransformToContext added in v0.3.0

func TransformToContext(ctx context.Context, w io.Writer, req Request) Result

TransformToContext is TransformTo that stops when ctx is done, like TransformContext.

type SecondaryOutput

type SecondaryOutput = engine.SecondaryOutput

SecondaryOutput is a document written by xsl:result-document.

type Security added in v0.2.0

type Security = engine.Security

Security limits the files and network resources a run may read.

type Stylesheet added in v0.0.8

type Stylesheet = engine.Stylesheet

Stylesheet is a stylesheet compiled once by Compile and run many times.

type TransformRequest added in v0.0.8

type TransformRequest = engine.TransformRequest

TransformRequest is a run of an already compiled Stylesheet: the per-run parts of a Request.

type ValidateRequest

type ValidateRequest = engine.ValidateRequest

ValidateRequest is one schema validation: the instance document, the schemas, the XSD version and the security settings.

type ValidateResult

type ValidateResult = engine.ValidateResult

ValidateResult says whether the instance is valid and lists every error found, in document order.

func Validate

func Validate(req ValidateRequest) ValidateResult

Validate validates an XML instance against XSD 1.0/1.1 schemas. It never panics; errors are reported as Diagnostics with Valid=false.

func ValidateContext added in v0.3.0

func ValidateContext(ctx context.Context, req ValidateRequest) ValidateResult

ValidateContext is Validate that stops when ctx is done, like TransformContext.

type XPathItem

type XPathItem = engine.XPathItem

XPathItem is one item of an XPath result with its type.

type XPathRequest

type XPathRequest = engine.XPathRequest

XPathRequest is one standalone XPath 3.1 evaluation: the expression, an optional context document, namespace and variable bindings.

type XPathResult

type XPathResult = engine.XPathResult

XPathResult is the value of an XPath evaluation, as a string and as a list of items.

func EvalXPath

func EvalXPath(req XPathRequest) XPathResult

EvalXPath evaluates a standalone XPath 3.1 expression, optionally against an XML context document (req.Source). It never panics; errors are reported as Diagnostics.

func EvalXPathContext added in v0.3.0

func EvalXPathContext(ctx context.Context, req XPathRequest) XPathResult

EvalXPathContext is EvalXPath that stops when ctx is done, like TransformContext.

type XSDVersion

type XSDVersion = engine.XSDVersion

XSDVersion selects XSD 1.0 or XSD 1.1 validation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL