Transforming Documents with XSL/XSLT
Earlier in this chapter, we used a Transformer object to copy a DOM representation
of an example back to XML text. We mentioned that we were not really
tapping the potential of the Transformer. Now, we’ll
give you the full story.
The javax.xml.transform
package is the API for using the XSL/XSLT transformation language. XSL
stands for Extensible Stylesheet Language. Like Cascading Stylesheets (CSS) for HTML, XSL allows us to
“mark up” XML documents by adding tags that provide presentation
information. XSL Transformation (XSLT) takes this further by adding the
ability to completely restructure the XML and produce arbitrary output.
XSL and XSLT together make up their own programming language for
processing an XML document as input and producing another (usually XML)
document as output. (From here on in, we’ll refer to them collectively as
XSL.)
XSL is extremely powerful, and new applications for its use arise every day. For example, consider a website that is frequently updated and that must provide access to a variety of mobile devices and traditional browsers. Rather than recreating the site for these and additional platforms, XSL can transform the content to an appropriate format for each platform. More generally, rendering content from XML is simply a better way to preserve your data and keep it separate from your presentation information. XSL can be used to render an entire website in different styles from files containing “pure data” in XML, ...