XSLT Transformer (XML + XSL)
Apply a real XSLT stylesheet to an XML document, right in your browser.
Apply a real XSLT stylesheet to an XML document, right in your browser.
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.
<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.
| Instruction | Use |
|---|---|
<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.
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.
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.
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.
No. Both documents are parsed and transformed in your browser.