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

Testing and Debugging

The software development community has shown a renewed interest in testing during the past few years. Much of this has been driven by the eXtreme Programming methodology, which emphasizes lightweight processes and constant unit testing to promote quality.[48] To demonstrate how to test XSLT transformations, a few simple files will be used. The XML data is shown first in Example 9-4.

Example 9-4. aidan.xml

<?xml version="1.0" encoding="UTF-8"?>
<person>
	<firstName>Aidan</firstName>
	<middleName>Garrett</middleName>
	<lastName>Burke</lastName>
	<birthDate month="6" day="25" year="1999"/>
</person>

Although this data is trivial, the same concepts apply to larger, more realistic examples. The sample XSLT stylesheet is shown in Example 9-5.

Example 9-5. condensePerson.xslt

<?xml version="1.0" encoding="UTF-8"?> <!-- *********************************************************** ** Transforms an XML file representing a person into a ** more concise format. ********************************************************--> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="includeMiddle" select="'yes'"/> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" doctype-system="condensed.dtd"/> <!-- match an existing <person> element --> <xsl:template match="person"> <!-- produce a new <person> element in a condensed form --> <xsl:element name="person"> <xsl:element name="name"> <xsl:value-of select="firstName"/> <xsl:text> ...

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