Chapter 58: XSL(T) Languages

What does “XSL(T)” actually mean?

XSL = Extensible Stylesheet Language XSLT = XSL Transformations (the most important part)

These are three related but different specifications that were created together in the late 1990s / early 2000s:

Name Full name Main purpose Current version (2025–2026) Still actively used?
XSLT XSL Transformations Transform XML into other XML / HTML / text / JSON XSLT 3.0 (2017) Very much alive
XSL-FO XSL Formatting Objects Describe page layout → create PDF XSL-FO 1.1 (2006) Niche / declining
XPath XML Path Language Select nodes in XML (used inside XSLT) XPath 3.1 (2017) Extremely common

Most people say “XSLT” when they actually mean the whole family — because XSLT is the part that is used the most.

Lesson 1 – The big picture: What does XSLT do?

XSLT takes an XML document as input and produces a completely new document as output.

Most common outputs in real life:

  • HTML (to display data in browser)
  • Another XML (change structure, filter, rename tags, add/remove elements)
  • Plain text (CSV, logs, email body…)
  • JSON (XSLT 3.0+)
  • PDF (via XSL-FO + processor like Apache FOP)

Everyday analogy

Imagine you have a raw shopping receipt written in XML:

XML

You want to turn this into a nice printable bill that your customer can understand:

  • Heading “Your Purchase”
  • Numbered list
  • Total at the bottom
  • Thank you message

XSLT is the smart assistant who reads your raw receipt and follows your instructions to produce the nice bill.

You don’t write loops or variables like in Python/JavaScript — you write rules:

“When you see <receipt>, output

Your Purchase

” “When you see <item>, output

  • + name + quantity + price +

” “At the end, calculate sum and output

Total: …

This is the declarative style of XSLT — you describe what the result should look like, not how to build it step by step.

Lesson 2 – The absolute minimal XSLT stylesheet (copy-paste & understand)

XML

What this does (very important to understand):

  • The processor starts reading any XML document
  • It looks for a template that matches the root of the document (/)
  • It finds this template → runs the code inside
  • It outputs a complete HTML page — even if the input was <nothing/>

This is the entry point of every XSLT transformation.

Lesson 3 – Real example 1: Transform product list → nice HTML table

Input XML (products.xml)

XML

XSLT stylesheet (products-to-html.xsl)

XML

Result HTML (what the browser sees)

HTML

Lesson 4 – Core XSLT building blocks (with examples)

4.1 <xsl:template match=”pattern”> – the heart of XSLT

XML
  • match=”product” → this rule runs when the processor sees a <product>
  • <xsl:value-of select=”price”/> → copy the text content of the <price> child

4.2 <xsl:apply-templates> – “now process my children”

XML

Without apply-templates, the <product> elements would be ignored.

4.3 <xsl:value-of select=”expression”/> – output text

XML

4.4 <xsl:if> – simple condition

XML

4.5 <xsl:choose> – if / else-if / else

XML

4.6 <xsl:for-each> – classic loop (use sparingly)

XML

Best practice: Prefer <xsl:apply-templates> over <xsl:for-each> when possible — it’s more modular and reusable.

Lesson 5 – Try yourself exercises (do these!)

  1. Output only the product names in a bullet list
  2. Show name + price with currency symbol
  3. If stock < 20, show “Low stock!” in red
  4. Create a table with columns: Name, Price, Stock
  5. Add a message “Free shipping” if price > 2000
  6. Show only products from category “electronics”

Lesson 6 – Real-world context (where XSLT is still used in 2025–2026)

  • e-Invoicing — GST XML → human-readable HTML/PDF
  • Financial messages — ISO 20022 → reports
  • Publishing — DocBook/DITA → HTML/PDF/EPUB
  • Legacy SOAP services — transform XML → preview
  • EDI / B2B — EDIFACT → XML → confirmation page
  • Configuration — XML config → documentation

Would you like to continue with one of these next?

  • Identity transform (copy everything + make small changes)
  • Grouping (group products by category – XSLT 2.0/3.0)
  • XSLT variables & parameters
  • XSLT with namespaces (real e-invoice, SOAP, Android manifest…)
  • XSLT 1.0 vs 2.0 vs 3.0 – what’s new & why it matters
  • Real-world example — GST invoice → nice HTML

Just tell me which direction feels most useful or interesting for you right now! 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *