What is XSLT?
To explain what XSLT is, we must first talk about XSL.
What is XSL?
XSL stands for EXtensible Stylesheet Language. It is a style language for XML (just as CSS is a style language for HTML).
In XML documents tags are not predefined. World Wide Web Consortium (W3C) developed XSL to understand and to style an XML document, which can act as XML based Stylesheet Language.
XSL describes how the XML elements should be displayed.
Main parts of XSL Document
XSL consists of four parts:
- XSLT: a language for transforming XML documents
- XPath: - a language for navigating in XML documents
- XSL-FO: - a language for formatting XML documents (discontinued in 2013)
- XQuery: - a language for querying XML documents
You can learn more about XPath and XQuery in our XPath Tutorial and XQuery Tutorial
What is XSLT?
XSLT (eXtensible Stylesheet Language Transformations) provides the ability to transform XML data from one format to another automatically.
XSLT is a W3C Recommendation.
XSLT uses XPath to navigate and to find information in XML documents.
How does XSLT work?
A common way to describe the transformation process is to say that XSLT transforms an XML source tree into an XML result tree.
The XSLT stylesheet is written in XML format. The XSLT processor takes the XSLT stylesheet and applies transformation rules on the target XML document and then generates a formatted document in XML, HTML or text format. This formatted document is then used by the XSLT formatter to generate the actual output that is to be displayed to the end user.
Advantage of XSLT
The advantages of using XSLT are:
- XSLT provides an easy way to merge XML data into your presentation because it applies user-defined transformations to an XML document and the output can be HTML, XML or any other structured document.
- XSLT provides XPath to locate elements/attributes within an XML document. So it is a more convenient way to traverse an XML document than a traditional way, using a scripting language.
- XSLT is template based. So it is more resilient to changes in documents than low level DOM and SAX.
- XSLT can be used as a validation language as it uses tree-pattern-matching approach.
- You can change the output simply modifying the transformations in XSL files.