/*
Java, XML, and Web Services Bible
Mike Jasnowski
ISBN: 0-7645-4847-6
*/
<%@ page contentType="image/svg-xml" %>
<%@ page import="org.xml.sax.*" %>
<%@ page import="org.apache.xalan.xslt.*" %>
<%@ page import="java.io.*" %>
<%
try {
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
processor.process(new XSLTInputSource("games.xml"),
new XSLTInputSource("games.xsl"),
new XSLTResultTarget(bos));
out.println(bos);
} catch (Exception ex) {
out.println(ex);
}
%>
<?xml version="1.0"?>
<games>
<game genre="rpg">XML Invaders</game>
<game genre="rpg">A Node in the XPath</game>
<game genre="rpg">XPath Racers</game>
</games>
//games.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<svg width="200" height="200">
<g>
<xsl:for-each select="games/game">
<text x="10" y="{number(10)*position()}">
<xsl:value-of select="text()"/>
</text>
</xsl:for-each>
</g>
</svg>
</xsl:template>
</xsl:stylesheet>
|