XSLT Basics

The  Extensible Stylesheet Language Transformations (XSLT) standard defines mechanisms for addressing XML data (XPath) and for specifying transformations on the data in order to convert it into other forms.


The Extensible Stylesheet Language (XSL) has three major subcomponents:


The Formatting Objects standard. XSL-FO gives mechanisms for describing font sizes, page layouts, and other aspects of object rendering.


This is the transformation language, which lets you define a transformation from XML into some other format. For example, you might use XSLT to produce HTML or a different XML structure. You could even use it to produce plain text or to put the information in some other document format.


At bottom, XSLT is a language that lets you specify what sorts of things to do when a particular element is encountered. But to write a program for different parts of an XML data structure, you need to specify the part of the structure you are talking about at any given time. XPath is that specification language. It is an addressing mechanism that lets you specify a path to an

element so that, for example, <article><title> can be distinguished from <person><title>. In that way, you can describe different kinds of translations for the different <title> elements.


The Extensible Stylesheet Language Transformations (XSLT) APIs

Following Figure shows the XSLT APIs in action.

Figure  XSLT APIs


A TransformerFactory object is instantiated and used to create a Transformer. The source object is the input to the transformation process. A source object can be created from a SAX reader, from a DOM, or from an input stream. Similarly, the result object is the result of the transformation process. That object

can be a SAX event handler, a DOM, or an output stream. When the transformer is created, it can be created from a set of transformation instructions, in which case the specified transformations are carried out. If it is created without any specific instructions, then the transformer object simply copies

the source to the result.


The XSLT Packages

The XSLT APIs are defined in the packages .

javax.xml.transform : Defines the TransformerFactory and Transformer classes, which you use to get an object capable of doing transformations. After creating a transformer object, you invoke its transform() method, providing it with an input (source) and output (result).

javax.xml.transform.dom :Classes to create input (source) and output (result) objects from a DOM.

javax.xml.transform.sax: Classes to create input (source) objects from a SAX parser and output (result)  objects from a SAX event handler.

javax.xml.transform.dom : Classes to create input (source) and output (result) objects from a DOM.

javax.xml.transform.sax Classes to create input (source) objects from a SAX parser and output (result) objects from a SAX event handler.

javax.xml.transform.stream : Classes to create input (source) objects and output (result) objects from an I/O stream.


Enter your email address:

Delivered by FeedBurner

Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)