StyleScript and XSL


The Account History Example

With all of this new information under our belts, let's look back at the account history example from the previous chapter. In that example, the JSP template file had quite a bit of JSP code in it. It would be nice to use an XTP page instead to remove much of the code and give the Web designers full control over it.

Here's a possible XTP page:

 <?xml-stylesheet href='history.xsl'?> <head> <title>Order History</title> </head> <body> <table border="1"> <order-history>   <tr>     <td>${orders.getString("date")}</td>     <td>${orders.getString("description")}</td>     <td>${orders.getString("price")}</td>   </tr> </history> </table> </body> 

Here's the corresponding XSL file for the page:

 <xsl:template match="loop-history">         <jsp:scriptlet>           ResultSet orders = (ResultSet)             request.getAttribute("orderHistory");           while (orders.next()) {         </jsp:scriptlet>             <xsl:apply-templates select="node()"/>         <jsp:scriptlet>           }         </jsp:scriptlet>       </xsl:template> 

  • Or, actually, a better example might be:

          <order-history>        <tr>            <td><order property="date"/></td>            <td><order property="description"/></td>            <td><order property="price"/></td>        </tr>      </order-history> 

Looking first at the XTP page, we see that all of the specific Java code found in the original JSP file has been replaced with a single tag called <order-history>. When the XTP page is browsed by a user, the XTP is processed along with the history.xsl file. The <order-history> tag causes the appropriate XSL to be executed with the proper results placed in the page. The result of the process is a JSP page and ultimately a servlet that produces the history of the current user.




Mastering Resin
Mastering Resin
ISBN: 0471431036
EAN: 2147483647
Year: 2002
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net