September 2001
Intermediate to advanced
528 pages
13h 46m
English
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> ...