XSLT
XSLT (Extensible Stylesheet Language Transformations) is a
language for transforming XML documents into other XML
documents. Again, w3schools is a fine
place to start if you're not familiar with XSLT yet. XSLT uses
XPath for matching the elements in a source document that should
be transformed (into a result document).
Here's an
example of a stylesheet, dvds.xsl, which can be
used to transform the dvds.xml file to an HTML
file:
Listing 4: The dvds.xsl stylesheet
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My DVD Collection</h2>
<table border="1">
<tr bgcolor="lightblue">
<th align="left">Id</th>
<th align="left">Title</th>
<th align="left">Length</th>
</tr>
<xsl:for-each select="collection/dvd">
<tr>
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="length"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Notice the XPath expressions: "collection/dvd", "@id", etc.
It's possible to let browsers like MSIE v. 6 or Mozilla Firebird
do the transformation if we simply add the stylesheet to the
dvds.xml file--like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="dvds.xsl"?>
<collection>
. . .
In one of these browsers the XML file will appear like this:
Figure 3: Browser view
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.