A proof-of-concept XSLT processor written in Go.
Note: This is an experimental implementation and not intended for production use. It supports only a subset of the XSLT specification.
xsl:template(match and named templates with priority)xsl:apply-templateswithxsl:sortandxsl:with-paramxsl:call-templatewithxsl:with-paramxsl:value-ofxsl:for-eachwithxsl:sortxsl:for-each-group(group-by,current-group(),current-grouping-key())xsl:if,xsl:choose/xsl:when/xsl:otherwisexsl:variable,xsl:param(withastype declarations)xsl:copy,xsl:copy-ofxsl:element,xsl:attributexsl:text,xsl:sequencexsl:comment,xsl:processing-instructionxsl:number(single/multiple/any level, format patterns)xsl:message(with terminate, custom message handler)xsl:result-document(multiple output documents)xsl:analyze-stringwithxsl:matching-substring/xsl:non-matching-substringandregex-group()xsl:map,xsl:map-entry(XPath maps and arrays supported)xsl:function(stylesheet functions callable from XPath)
xsl:output(method, indent, version, omit-xml-declaration)xsl:importandxsl:include(with precedence and cycle detection)- Stylesheet parameters (
xsl:paramat top level, passable via CLI or API) - Attribute Value Templates (
class="item-{@id}") - Literal result elements
- Match patterns with predicates (
book[@lang='en']), path patterns, union patterns
go install github.com/speedata/goxslt/cmd/goxslt@latest
goxslt -s source.xml -t stylesheet.xsl [-o output.xml] [param=value ...]
package main
import (
"fmt"
"os"
"github.com/speedata/goxml"
"github.com/speedata/goxslt"
)
func main() {
sourceDoc, _ := goxml.Parse(os.Stdin)
xsltFile, _ := os.Open("style.xsl")
xsltDoc, _ := goxml.Parse(xsltFile)
ss, _ := goxslt.Compile(xsltDoc)
result, _ := goxslt.Transform(ss, sourceDoc)
fmt.Print(goxslt.SerializeIndent(result.Document, " "))
// Secondary documents produced by xsl:result-document
for href, doc := range result.SecondaryDocuments {
os.WriteFile(href, []byte(goxslt.SerializeResult(doc)), 0644)
}
}To run the W3C XSLT 3.0 conformance tests, clone the test suite into testdata/w3c/:
git clone https://github.com/w3c/xslt30-test.git testdata/w3c
Then run:
go test -v -run TestW3C ./...
The directory is listed in .gitignore. If it is not present, the tests are skipped automatically.
MIT — see LICENSE.