April 2005
Intermediate to advanced
336 pages
7h 20m
English
The xslt task, also
called the style task (the two names
are interchangeable in Ant), can process a set of documents via XSLT.
This is handy for building nicely formatted views of XML-based
documentation in other formats like HTML, or for generating code. How do
you use this task to perform XSLT transformations? Example 9-5 shows a build file that
puts it to work, transforming style.xml into
style.html, using
style.xsl.
Example 9-5. Using the xslt/style task ch09/xslt/build.xml
<?xml version="1.0" encoding="UTF-8" ?>
<project default="main" >
<target name="main">
<xslt basedir="." destdir="." extension=".html" includes="style.xml"
style="style.xsl"/>
</target>
</project>Here's style.xml, the XML document to transform, which holds data about three U.S. states:
<?xml version="1.0" encoding ="UTF-8"?> <states> <state> <name>California</name> <population units="people">33871648</population><!--2000 census--> <capital>Sacramento</capital> <bird>Quail</bird> <flower>Golden Poppy</flower> <area units="square miles">155959</area> </state> <state> <name>Massachusetts</name> <population units="people">6349097</population><!--2000 census--> <capital>Boston</capital> <bird>Chickadee</bird> <flower>Mayflower</flower> <area units="square miles">7840</area> </state> <state> <name>New York</name> <population units="people">18976457</population><!--2000 census--> <capital>Albany</capital> <bird>Bluebird</bird> <flower>Rose</flower> <area units="square miles">47214</area> ...