Dynamic Web Sites with XML, XSLT and JSP (4/4) - exploring XML
Dynamic Web Sites with XML, XSLT and JSP
Now begins the work of the Web designer, who needs to save the XSLT style sheet under xslt/xml/book.xsl for reference by the JSP:
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="https://www.w3.org/1999/XSL/Transform"> <xsl:template match="book"> <table> <tr><th>Name</th><th>Phone</th></tr> <xsl:for-each select="phone"> <tr> <td><xsl:value-of select="name" /></td> <td><xsl:value-of select="number" /></td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>
This stylesheet loops over all phone book entries and drops the names and numbers into a simple HTML table structure.
If everything is plugged together correctly the result of requesting https://localhost:8080/xslt/book.jsp displays:
Name | Phone |
---|---|
Police | 110 |
Fire Brigade | 112 |
Conclusion
The technique presented here exploits XML and XSLT for creating dynamic Web sites. The simple JSP shown here can be easily extended to generate the XML data from a database, or by parsing live HTML from other sites and converting it into XML. The possibilities are endless.
See also column 18 for another method of combining XML, XSLT and JSP.
Produced by Michael Claßen
URL: https://www.webreference.com/xml/column37/4.html
Created: Aug 15, 2001
Revised: Aug 15, 2001