# XSLT transformer

Source: https://xmlvalid.com/tools/xslt-transformer

> Apply a stylesheet to an XML document and see what it makes: the result with a preview of HTML, the files xsl:result-document writes and what xsl:message says. XSLT 3.0 runs as written, and so do 1.0 and 2.0 stylesheets. Everything runs in your browser.

## How to run a transformation

1. Paste or open the XML and the stylesheet. The example turns a UBL invoice into an HTML page and a CSV file.
2. Add parameters if the stylesheet takes any: one `name = value` per line, passed to its `xsl:param` as strings.
3. Press **Transform** (or Ctrl+Enter in an editor). The result opens below; HTML gets a **Preview**, and each file from `xsl:result-document` a tab of its own.

## XSLT 3.0, 2.0 and 1.0

Stylesheets are compiled and run by SaxonJS 2.7, Saxonica's XSLT 3.0 processor for JavaScript, in a background worker. What XSLT 3.0 adds works: text value templates (`expand-text`), `xsl:iterate`, `xsl:for-each-group`, maps and arrays, functions as values and the whole of [XPath 3.1](https://xmlvalid.com/tools/xpath-tester). A 1.0 stylesheet runs in backwards-compatible mode, as the XSLT 3.0 specification provides.

Not available: schema-aware processing (`xsl:import-schema`) and streaming, which need Saxon-EE, and other local files: `xsl:include`, `xsl:import` and `document()` can't reach files on your disk, so put the modules into one stylesheet to try them here.

## Messages, errors and result documents

- **xsl:message** lines appear above the result, in order. With `terminate="yes"` the run stops with its text.
- **Errors** show their code and message: static errors (`XTSE0010`, `XPST0003`) with the line in the stylesheet, dynamic ones (`FORG0001`, `XPTY0004`) as they happen. A stylesheet that runs forever can be stopped.
- **Result documents** written by `xsl:result-document href="…"` get a tab each and download under their own name.
- **HTML** results can be previewed. The preview runs without scripts and without access to this page.

## Questions

### Is my XML uploaded?

No. The stylesheet is compiled and run by SaxonJS in your browser; neither file leaves your machine.

### Which XSLT version is supported?

XSLT 3.0 with XPath 3.1, through SaxonJS 2.7. XSLT 1.0 and 2.0 stylesheets run too.

### Can I use xsl:include or xsl:import?

Not of local files: only the pasted stylesheet is available. Merge the modules into one stylesheet to try it here.

### Is it the same as Saxon on a server?

SaxonJS implements the same XSLT 3.0 specification as Saxon-HE for Java. Schema-aware processing and streaming, which need Saxon-EE, are not available.

### Other tools

- [XML formatter](https://xmlvalid.com/tools/xml-formatter): Pretty-print or minify XML, keeping text, CDATA and comments as written.
- [XPath tester](https://xmlvalid.com/tools/xpath-tester): Evaluate XPath 3.1 against a document and see each match with its line.
- [XSD generator](https://xmlvalid.com/tools/xsd-generator): Infer an XML Schema from sample documents, checked against them.
- [XML from XSD](https://xmlvalid.com/tools/xsd-to-xml): Generate a sample XML document from a schema, validated against it.
- [XML diff](https://xmlvalid.com/tools/xml-diff): Compare two XML documents as trees: changed, added and removed elements, attributes and text.
- [XML to JSON converter](https://xmlvalid.com/tools/xml-to-json): Convert XML to JSON, with arrays where an element repeats or wherever its XSD allows.
- [JSON to XML converter](https://xmlvalid.com/tools/json-to-xml): Convert JSON to XML: @keys become attributes, arrays repeated elements.
- [XML to CSV converter](https://xmlvalid.com/tools/xml-to-csv): Turn a repeating element into CSV rows: invoice lines, products, records.
- [E-invoice viewer](https://xmlvalid.com/tools/e-invoice-viewer): Read an XRechnung, ZUGFeRD, Factur-X or Peppol invoice as a document, and print it.
- [XML validator](https://xmlvalid.com/validate): check a document against XSD, DTD, RelaxNG or Schematron, up to 1 GB.
