XSLT Tutorial: Transform XML Into HTML, XML or Text
XSLT is used to transform XML documents into other formats such as HTML, XML, plain text or even different XML structures. It combines XML rules with XPath expressions to control how data is processed.
- XSLT transforms XML into other formats.
- XSLT uses XPath to select XML data.
- XSLT stylesheets are written in XML.
- XSLT is commonly used for reports, integrations and XML processing.
What is XSLT?
XSLT stands for Extensible Stylesheet Language Transformations.
It is a language designed to transform XML documents into other formats such as:
- HTML
- Plain text
- Different XML structures
- Data feeds
Think of XSLT like a chef following a recipe. The XML is the raw ingredients, and XSLT decides how everything gets sliced, arranged and served.
Sample XML document
The examples below use this XML:
<employees>
<employee>
<name>Jane Smith</name>
<role>Chief Cheese Tester</role>
</employee>
<employee>
<name>Mia Cheese</name>
<role>Bridge Snack Coordinator</role>
</employee>
</employees>
Basic XSLT structure
XSLT stylesheets are themselves written in XML.
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
</xsl:template>
</xsl:stylesheet>
What is an XSLT template?
Templates define what should happen when matching XML nodes are found.
The match attribute uses XPath expressions.
<xsl:template match="employee">
Employee Found
</xsl:template>
Transforming XML into HTML
XSLT is commonly used to generate HTML pages from XML data.
<xsl:template match="/">
<html>
<body>
<h1>Employees</h1>
<ul>
<xsl:for-each select="employees/employee">
<li>
<xsl:value-of select="name" />
</li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
What does xsl:value-of do?
The xsl:value-of element extracts data from XML nodes.
<xsl:value-of select="name" />
This outputs the text value of the name element.
What does xsl:for-each do?
The xsl:for-each element loops through matching XML nodes.
<xsl:for-each select="employees/employee">
</xsl:for-each>
This loops through every employee element.
How XSLT uses XPath
XSLT heavily relies on XPath expressions.
| XPath | Meaning |
|---|---|
/ |
The root node. |
employees/employee |
Select all employee elements. |
name |
Select the current employee name. |
@id |
Select an attribute value. |
Common XSLT use cases
- Generating HTML reports from XML
- Transforming XML between systems
- Formatting XML feeds
- Enterprise integrations
- Legacy system modernisation
- Publishing structured XML content
XSLT vs CSS
| Feature | XSLT | CSS |
|---|---|---|
| Transforms XML | Yes | No |
| Can change structure | Yes | No |
| Uses XPath | Yes | No |
| Main purpose | Data transformation | Visual styling |
XSLT is extremely powerful, but modern web applications often prefer JSON and JavaScript rendering instead of XML transformations in the browser.
Format or view XML online
Use CheeseBridge XML tools to inspect XML documents before working with XSLT transformations.
Open XML Viewer Open XML FormatterTrusted references
For official and technical references, see:
Frequently asked questions
What is XSLT used for?
XSLT is used to transform XML documents into formats such as HTML, XML or plain text.
Does XSLT use XPath?
Yes. XSLT uses XPath expressions to select and process XML nodes.
Can XSLT create HTML?
Yes. One of the most common XSLT use cases is transforming XML data into HTML pages.