xslts

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package xslts runs the W3C XSLT test suite against this engine, filtered to the tests an XSLT 2.0 processor is expected to pass.

There is no maintained XSLT 2.0 suite. The original XSLTS was frozen at 1.1.0, was distributed from w3.org behind a click-through licence rather than a repository, and has had no maintenance since XSLT 2.0 reached Recommendation in 2007. What replaced it is the XSLT 3.0 suite, which carried most of those tests forward and records a version dependency on each one — so a 2.0-conformance run is a filtered run of the 3.0 suite rather than a separate corpus.

The suite is not vendored: it is ~470MB and belongs to the W3C. Point GOXSLT_XSLTS at a checkout of https://github.com/w3c/xslt30-test and the tests in this package run; without it they skip.

git clone --depth 1 https://github.com/w3c/xslt30-test.git
GOXSLT_XSLTS=xslt30-test go test ./xslts/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

type Assertion struct {
	// Kind is the element name: "assert", "assert-xml", "error", "all-of".
	Kind string
	// Value is the character data, which for most kinds is the expected
	// result or the XPath expression to evaluate against it.
	Value string
	// Code is the @error-code of an <error>.
	Code string
	// File names a document holding the expected value, used where it is too
	// large to sit inline.
	File string
	// Normalize records @normalize-space on an assert-xml, which says
	// whitespace differences do not count.
	Normalize bool
	// URI is the @uri of an assert-result-document, naming which secondary
	// output the nested assertions apply to.
	URI string
	// Flags is the @flags of a serialization-matches, in the XPath regular
	// expression flag vocabulary: i, s, m and x.
	Flags string
	// Encoding is the @encoding of an assert-serialization, naming the
	// character encoding the expected-result file is written in. Without it
	// the file is UTF-8, which is what almost every one of them is.
	Encoding string
	// NS holds the prefix-to-URI bindings in scope where the assertion was
	// written. The suite declares them on the assertion element or on an
	// enclosing combinator — an XPath assertion that names a prefix cannot be
	// evaluated without them.
	NS map[string]string
	// Children are the operands of all-of, any-of and not.
	Children []Assertion
}

Assertion is one node of a result tree.

The suite nests all-of, any-of and not to arbitrary depth, so the result is walked with the token stream rather than described with struct tags.

func ParseAssert

func ParseAssert(raw []byte, outer map[string]string) (Assertion, error)

ParseAssert parses the raw result XML into an assertion tree.

outer holds the namespace bindings in scope at the element raw was taken from the inside of — the suite declares the XHTML prefix on <result> itself, and innerxml does not carry it.

type Catalog

type Catalog struct {
	XMLName      xml.Name      `xml:"catalog"`
	TestSets     []TestSetRef  `xml:"test-set"`
	Environments []Environment `xml:"environment"`
}

Catalog is the top-level catalog.xml.

type Collection

type Collection struct {
	URI     string   `xml:"uri,attr"`
	Sources []Source `xml:"source"`
}

Collection is a named set of documents fn:collection returns.

An empty uri names the *default* collection — the one collection() with no argument returns — which is why the attribute is not treated as missing when it is present and blank.

type Dependencies

type Dependencies struct {
	Specs    []Spec    `xml:"spec"`
	Features []Feature `xml:"feature"`
	Others   []Other   `xml:",any"`
}

Dependencies is the set of conditions a test needs.

Only the ones that decide whether a test is in scope here are modelled. Everything else — the many feature and implementation-defined flags — is read as a raw name so that an unrecognised one excludes the test rather than being silently ignored.

type Environment

type Environment struct {
	Name    string   `xml:"name,attr"`
	Ref     string   `xml:"ref,attr"`
	Sources []Source `xml:"source"`
	Params  []Param  `xml:"param"`
	Schemas []Schema `xml:"schema"`
	// Collections are the document sets fn:collection resolves. An
	// environment declaring one is what makes collection() answer at all:
	// without it the engine refuses, correctly, because a collection URI it
	// was never told about is not a document set it can invent.
	Collections []Collection `xml:"collection"`
	// Stylesheets declared here are shared by every case referencing the
	// environment. A test-set built that way states no stylesheet on its
	// cases at all, so a runner reading only the case-level ones finds none
	// and reports the whole set as unrunnable.
	Stylesheets []StylesheetRef `xml:"stylesheet"`
}

Environment supplies the source documents, parameters and settings a test runs against.

type Feature

type Feature struct {
	Value     string `xml:"value,attr"`
	Satisfied string `xml:"satisfied,attr"`
}

type NamedThing

type NamedThing struct {
	// Name is the lexical QName exactly as the catalog wrote it.
	Name string `xml:"name,attr"`
	// URI is the namespace the catalog's own declarations bind Name's prefix
	// to. It is filled in by resolveInitialTemplateNames rather than by
	// encoding/xml, which never resolves a QName held in an attribute value.
	// Empty means the name has no prefix, or the prefix was unbound.
	URI string `xml:"-"`
}

type Other

type Other struct {
	XMLName   xml.Name
	Value     string `xml:"value,attr"`
	Satisfied string `xml:"satisfied,attr"`
}

Other is any dependency element this runner does not model.

type Outcome

type Outcome struct {
	Set, Name string
	Pass      bool
	Skipped   bool
	// Why explains a skip or a failure.
	Why string
}

Outcome is what happened to one test.

type OutputRef

type OutputRef struct {
	File      string `xml:"file,attr"`
	Serialize string `xml:"serialize,attr"`
}

type PackageRef

type PackageRef struct {
	File string `xml:"file,attr"`
	Role string `xml:"role,attr"`
}

type Param

type Param struct {
	Name   string `xml:"name,attr"`
	Select string `xml:"select,attr"`
	As     string `xml:"as,attr"`
	Static string `xml:"static,attr"`
}

type Result

type Result struct {
	Inner string `xml:",innerxml"`
	// NS holds the prefix-to-URI bindings in scope at the <result> element
	// itself. encoding/xml's innerxml keeps only what is *inside* the
	// element, so a declaration written on <result> — which is where the
	// suite puts the XHTML binding an assertion's XPath needs — is not in
	// Inner and cannot be recovered by parsing it. Filled in by
	// resolveResultNamespaces.
	NS map[string]string `xml:"-"`
}

Result is the assertion tree, kept as raw XML.

The nesting is arbitrary — all-of and any-of contain further assertions to any depth — so it is walked with the token stream rather than described with struct tags.

type Runner

type Runner struct {
	// Root is the suite checkout.
	Root string
	// Timeout bounds one transform. A stylesheet that does not terminate is a
	// failure of that test rather than of the run.
	Timeout time.Duration
}

Runner executes the suite against this engine.

func (*Runner) Run

func (r *Runner) Run() (*Summary, error)

type Schema

type Schema struct {
	URI  string `xml:"uri,attr"`
	File string `xml:"file,attr"`
}

type SetStats

type SetStats struct{ Passed, Failed, Skipped int }

SetStats counts one test-set.

type Source

type Source struct {
	Role    string `xml:"role,attr"`
	File    string `xml:"file,attr"`
	URI     string `xml:"uri,attr"`
	Content string `xml:"content"`
	// Select is an XPath expression that picks the initial context node out
	// of the loaded document -- or, with no file and no inline content,
	// constructs it outright (parse-xml('<root/>')). The initial context
	// item need not be a document node, and three cases in the suite name an
	// element or a text node this way.
	Select string `xml:"select,attr"`
	// Validation is "strict", "lax" or "skip". A source declared strict is
	// meant to reach the transform carrying type annotations from the
	// environment's schema, which is what makes "instance of my:type"
	// answer true for a value read out of it.
	Validation string `xml:"validation,attr"`
}

Source is one input document, either named by file or given inline.

role="." marks the principal input — the document the transform starts on. Any other role names a secondary document reachable through fn:doc.

type Spec

type Spec struct {
	Value string `xml:"value,attr"`
}

type StylesheetRef

type StylesheetRef struct {
	File    string `xml:"file,attr"`
	Role    string `xml:"role,attr"`
	Content string `xml:",innerxml"`
}

type Summary

type Summary struct {
	Total, Passed, Failed, Skipped int
	// Failures holds the failing outcomes, for reporting.
	Failures []Outcome
	// SkipReasons counts why tests were left out, so that the scope of a run
	// is visible rather than implied by the total.
	SkipReasons map[string]int
	// BySet counts each test-set separately. A single percentage hides which
	// features work: a set failing 96 of 100 is an unimplemented feature,
	// while one failing 5 of 300 is a handful of edge cases, and the two want
	// entirely different work.
	BySet map[string]*SetStats
}

Summary counts a run.

type Test

type Test struct {
	Stylesheets     []StylesheetRef `xml:"stylesheet"`
	Packages        []PackageRef    `xml:"package"`
	InitialTemplate *NamedThing     `xml:"initial-template"`
	InitialMode     *NamedThing     `xml:"initial-mode"`
	InitialFunction *NamedThing     `xml:"initial-function"`
	Params          []Param         `xml:"param"`
	Output          *OutputRef      `xml:"output"`
	// PostureAndSweep marks a streamability test, which is XSLT 3.0 only.
	PostureAndSweep *struct{} `xml:"posture-and-sweep"`
	XPath           string    `xml:"xpath"`
}

Test says what to run.

type TestCase

type TestCase struct {
	Name         string        `xml:"name,attr"`
	Description  string        `xml:"description"`
	Environments []Environment `xml:"environment"`
	Dependencies Dependencies  `xml:"dependencies"`
	Test         Test          `xml:"test"`
	Result       Result        `xml:"result"`
}

TestCase is one test.

type TestSet

type TestSet struct {
	XMLName      xml.Name      `xml:"test-set"`
	Name         string        `xml:"name,attr"`
	Environments []Environment `xml:"environment"`
	// Dependencies declared here apply to every case in the set unless the
	// case states its own. Seven thousand cases inherit rather than declare,
	// so a runner that reads only the case-level ones admits tests that need
	// XSLT 3.0 and reports them as failures of this engine.
	Dependencies Dependencies `xml:"dependencies"`
	Cases        []TestCase   `xml:"test-case"`

	// Dir is the test-set file's directory, relative to the suite root.
	// Stylesheet and source paths are relative to it rather than to the root.
	Dir string `xml:"-"`

	// Path is the test-set file itself. An inline <source><content> is a part
	// of this file, so this -- not a synthesised name in Dir -- is the base
	// URI the XML spec gives the element the content becomes.
	Path string `xml:"-"`
}

TestSet is one test-set file.

type TestSetRef

type TestSetRef struct {
	Name string `xml:"name,attr"`
	File string `xml:"file,attr"`
}

Jump to

Keyboard shortcuts

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