XSLT Transformer (XML + XSL)

Apply a real XSLT stylesheet to an XML document, right in your browser.

How to run an XSL transformation

  1. Paste the XML document in the first box and the XSLT stylesheet in the second, or click Load sample for a catalog-to-HTML-table example.
  2. Click Transform. The result document is serialised into the output box, ready to copy.
  3. If either input is not well-formed, the error names which one failed (XML or stylesheet) and the parser message.

The transformation is done by the XSLT engine built into your browser (XSLTProcessor), the same one that renders XML files that reference a stylesheet with <?xml-stylesheet?>. Nothing is uploaded.

What the sample does

<xsl:template match="/catalog">
  <table border="1">
    <tr><th>Title</th><th>Price</th></tr>
    <xsl:for-each select="book">
      <tr><td><xsl:value-of select="title"/></td>
          <td><xsl:value-of select="price"/></td></tr>
    </xsl:for-each>
  </table>
</xsl:template>

The template matches the root catalog element, loops over each book and writes one table row with its title and price, giving an HTML table with "XML Basics 29.99" and "Learning XSLT 34.99". <xsl:output method="html"/> tells the processor to produce HTML rather than XML.

XSLT 1.0 building blocks

InstructionUse
<xsl:template match="...">Rule applied to nodes matching an XPath pattern
<xsl:apply-templates select="..."/>Process child nodes with the matching templates
<xsl:value-of select="..."/>Output the text value of an expression
<xsl:for-each select="...">Loop over a node set
<xsl:sort select="price" data-type="number"/>Sort inside for-each or apply-templates
<xsl:if test="..."> / <xsl:choose>Conditions
<xsl:copy-of select="."/>Copy nodes unchanged (identity transforms)
<xsl:attribute name="href"> or href="{@url}"Build attributes from data

Select and match expressions are XPath 1.0; test them first in the XPath tester.

Limits

Browsers support XSLT 1.0 only. Stylesheets declaring version="2.0" or 3.0 run in forwards-compatible mode, so 2.0 features such as xsl:for-each-group, regular expressions or user-defined functions fail. For those, use Saxon on the command line. document() and xsl:include of other files cannot be resolved because only the pasted text is available.

FAQ

Why is my output empty?

The most common cause is a namespace: if the XML has xmlns="...", your match patterns must use a prefix bound to that namespace in the stylesheet. Another is a template that matches nothing, so only the built-in rules run and output plain text.

Can I output JSON or CSV?

Yes. Set <xsl:output method="text"/> and write the separators yourself, for example with <xsl:text>,</xsl:text>. For a ready-made conversion, try the XML to CSV converter.

Is my data uploaded?

No. Both documents are parsed and transformed in your browser.