Mega Code Archive

 
Categories / Java / JSP
 

JSP XML and XSLT transform

/* <people>   <person>     <name>Peter</name>     <age>54</age>   </person>   <person>     <name>Patricia</name>     <age>50</age>   </person> </people> */ //globalParam.xsl /* <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">   <xsl:param name="ageParam">60</xsl:param>   <xsl:template match="people">     <h1>List of people in the XML document</h1>     <table border="1">       <th>Name</th><th>Age</th>       <xsl:apply-templates />     </table>   </xsl:template>   <xsl:template match="person">     <xsl:call-template name="processPerson">       <xsl:with-param name="ageParam">         51       </xsl:with-param>     </xsl:call-template>   </xsl:template>   <xsl:template name="processPerson">     <!-- <xsl:param name="ageParam" /> -->     <tr>       <td>         <xsl:value-of select="name/text()" />       </td>       <td>         <xsl:value-of select="age/text()"  />         <xsl:if test="age/text() > $ageParam">             (old!)           </xsl:if>       </td>     </tr>       </xsl:template> </xsl:transform> */ <%@ taglib uri="http://java.sun.com/jstl/xml"  prefix="x" %> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <html >   <head>     <title>Using a Named Template with Global Parameters</title>   </head>   <body>     <c:import url="http://localhost:8080/chapter02/people.xml"               var="inputDoc" />     <c:import url="http://localhost:8080/chapter02/globalParam.xsl"               var="stylesheet" />     <x:transform xml  = "${inputDoc}"                  xslt = "${stylesheet}">       <x:param name="ageParam"  value="49" />     </x:transform>   </body> </html>