JSP jstl-<x:param> 标记

  • jstl-<x:param> 标记

    <x:param> 标记用于沿与变换标签在XSLT样式表来设置的参数
  • 属性

    属性 描述 必需 默认值
    name 要设置的XSLT参数的名称 Yes Body
    Value 要设置的XSLT参数的值 No None
  • 示例

    考虑以下XSLT样式表style.xsl。注意<xsl:param ...> 标签和变量{$ bgColor}的用法-
    
    <?xml version = "1.0"?>
    <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0">
    
    <xsl:output method = "html" indent = "yes"/>
    <xsl:param name = "bgColor"/>
    
       <xsl:template match = "/">
          <html>
             <body>
                <xsl:apply-templates/>
             </body>
          </html>
       </xsl:template>
    
       <xsl:template match = "books">
          <table border = "1" width = "50%" bgColor = "{$bgColor}">
             <xsl:for-each select = "book">
                <tr>
                   <td><i><xsl:value-of select = "name"/></i></td>
                   <td><xsl:value-of select = "author"/></td>
                   <td><xsl:value-of select = "price"/></td>
                </tr>
             </xsl:for-each>
          </table>
       </xsl:template>
       
    </xsl:stylesheet>
    
    考虑以下JSP文件,我们在其中使用<x:transform>标记内的<x:param>标记定义bgColor的值-
    
    <%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix = "x" uri = "http://java.sun.com/jsp/jstl/xml" %>
    
    <html>
       <head>
          <title>JSTL x:transform Tags</title>
       </head>
    
       <body>
          <h3>Books Info:</h3>
          <c:set var = "xmltext">
             <books>
                <book>
                   <name>Padam History</name>
                   <author>MOO</author>
                   <price>100</price>
                </book>
                
                <book>
                   <name>Great Mistry</name>
                   <author>NUHA</author>
                   <price>2000</price>
                </book>
             </books>
          </c:set>
    
          <c:import url = "http://localhost:8080/style.xsl" var = "xslt"/>
          <x:transform xml = "${xmltext}" xslt = "${xslt}">
             <x:param name = "bgColor" value = "grey"/>
          </x:transform>
    
       </body>
    </html>
    
    上面的代码将产生以下结果-
    
    Books Info:
    
    Padam History  MOO  100
    Great Mistry   NUHA  2000