The following example uses the widget
orders
XML document shown earlier, and this XSLT template:
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="widget-orders"> <table> <tr> <td>Order Id</td> <td>Order Status</td> </tr> <xsl:for-each select="order[@account='86666']"> <xsl:sort select="@id"/> <tr> <td> <xsl:value-of select="@id"/> </td> <td> <xsl:value-of select="order-status"/> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>
The example uses the servlet bean XMLTransform as follows:
The servlet bean’s
input
parameter specifies the XML document to transform—widget
orders
—by supplying its relative URLorders.xml
.The
template
parameter supplies the XSLT template shown earlier,orders
template.xsl
.No
output
parameter is specified, so the servlet bean displays the transformed XML document in the current JSP.
<dsp:droplet name="/atg/dynamo/droplet/xml/XMLTransform"> <dsp:param name="input" value="orders.xml"/> <dsp:param name="template" value="orders-template.xsl"/> <dsp:oparam name="failure"> Failure to transform XML document: <dsp:valueof param="input"/> <br/> </dsp:oparam> </dsp:droplet>
The orders.xml
document is transformed by this template to yield the same output as shown in the XMLToDOM example shown earlier (in Processing XML in a JSP). The XSLT template performs the same selection and formatting as the servlet beans XMLToDOM, NodeForEach, and NodeMatch.