Chapter 57: XSLT Introduction

1. What is XSLT? (The clearest honest explanation)

XSLT = XSL Transformations (also sometimes just called XSL)

XSLT is a special-purpose language that was designed to do one main job:

Take an XML document as input Transform / rearrange / filter / calculate / rename / decorate it Produce a new document as output

The output is most commonly:

  • Another XML document
  • HTML (very very common – to display data in a browser)
  • Plain text
  • JSON (in modern XSLT 3.0)
  • PDF (indirectly via XSL-FO)

Real-life analogy everyone understands

Imagine you have a raw shopping list written in XML:

XML

You want to turn this raw list into a beautiful shopping note that your family can read on their phone:

  • Heading “Shopping for tomorrow”
  • Numbered list
  • Convert grams to kg
  • Add a friendly message

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

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

“When you see <shopping-list>, output

Shopping for tomorrow

” “When you see <item>, output

  • + the quantity + the name +

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

2. Why do people still use XSLT in 2025–2026? (honest answer)

Even though JSON is dominant for new APIs, XSLT is still very alive in certain worlds because:

Reason Typical situations / industries Still very active today?
Mandatory standards require XML + transformation e-Invoicing (UBL, GST, PEPPOL, Factur-X), ISO 20022, HL7 CDA Extremely high
Need very strict validation before/after transformation Financial messages, legal/government documents, healthcare Very high
Large documents + streaming transformation Batch invoices (thousands), customs declarations, catalog feeds Yes
Mixed content & document-oriented data Publishing (DocBook, DITA), technical manuals, legal XML Yes
Legacy enterprise systems Many banks, insurance, ERP, government portals Very common
Separation of data & presentation Designers can work on XSLT without touching backend code Still used

Bottom line (2025–2026 reality):

  • New web/mobile apps → almost always JSON + JavaScript/React
  • Enterprise / finance / government / healthcare / publishing / B2B → XSLT is still very common (and sometimes mandatory)

3. The absolute minimal XSLT stylesheet (copy-paste & understand)

XML

What this does:

  • When the XSLT processor starts reading any XML document, it finds the template that matches the root (/)
  • It runs the code inside that template
  • It outputs a complete HTML page — even if the input was <nothing/>

4. Real example 1 – Transform simple product list into HTML table

Input XML (products.xml)

XML

XSLT stylesheet (products-to-html.xsl)

XML

Result HTML (what the browser sees)

HTML

Lesson 5 – Core XSLT building blocks (with examples)

5.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

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

XML

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

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

XML

5.4 <xsl:if> – simple condition

XML

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

XML

5.6 <xsl:for-each> – classic loop

XML

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

Lesson 6 – 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 7 – 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)
  • Variables & parameters
  • XSLT with namespaces (real e-invoice, SOAP, Android manifest…)
  • XSLT 1.0 vs 2.0 vs 3.0 – what’s new
  • 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 *