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
- func Compile(req Request) (*Stylesheet, []Diagnostic)
- type Diagnostic
- type Features
- type Limits
- type Request
- type Result
- type SecondaryOutput
- type Security
- type Stylesheet
- type TransformRequest
- type ValidateRequest
- type ValidateResult
- type XPathItem
- type XPathRequest
- type XPathResult
- type XSDVersion
Constants ¶
const ( SeverityError = engine.SeverityError SeverityWarning = engine.SeverityWarning )
Severities of a Diagnostic.
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
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
Limits bounds what a run may execute (instruction steps, nesting depth).
type Request ¶
Request is one transformation: the stylesheet, the source document, parameters, the initial template/mode, and the security, limit and feature settings.
type Result ¶
Result is the outcome of a transformation: the principal output, the documents written by xsl:result-document, messages and Diagnostics.
func Transform ¶
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
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
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 ¶
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.
type SecondaryOutput ¶
type SecondaryOutput = engine.SecondaryOutput
SecondaryOutput is a document written by xsl:result-document.
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 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.