O'Reilly logo

Java and XSLT by Eric M. Burke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Schema Evolution

Looking beyond HTML generation, a key use for XSLT is transforming one form of XML into another form. In many cases, these are not radical transformations, but minor enhancements such as adding new attributes, changing the order of elements, or removing unused data. If you have only a handful of XML files to transform, it is a lot easier to simply edit the XML directly rather than going through the trouble of writing a stylesheet. But in cases where a large collection of XML documents exist, a single XSLT stylesheet can perform transformations on an entire library of XML files in a single pass. For B2B applications, schema evolution is useful when different customers require the same data, but in different formats.

An Example XML File

Let’s suppose that you wrote a logging API for your Java programs. Log files are written in XML and are formatted as shown in Example 3-10.

Example 3-10. Log file before transformation

<?xml version="1.0" encoding="UTF-8"?> <log> <message text="input parameter was null"> <type>ERROR</type> <when> <year>2000</year> <month>01</month> <day>15</day> <hour>03</hour> <minute>12</minute> <second>18</second> </when> <where> <class>com.foobar.util.StringUtil</class> <method>reverse(String)</method> </where> </message> <message text="cannot read config file"> <type>WARNING</type> <when> <year>2000</year> <month>01</month> <day>15</day> <hour>06</hour> <minute>35</minute> <second>44</second> </when> <where> <class>com.foobar.servlet.MainServlet</class> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required