JSP 標(biāo)準(zhǔn)標(biāo)簽庫(kù)
<x:param>標(biāo)簽與<x:transform>標(biāo)簽一同使用,用于設(shè)置XSLT樣式表的參數(shù)。
<x:param name="<string>" value="<string>"/>
<x:param>標(biāo)簽有如下屬性:
| 屬性 | 描述 | 是否必要 | 默認(rèn)值 |
|---|---|---|---|
| name | XSLT參數(shù)的名稱 | 是 | Body |
| value | XSLT參數(shù)的值 | 否 | 無(wú) |
style.xsl文件代碼如下,使用xsl:param...標(biāo)簽與{$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>mian.jsp文件代碼如下,在x:transform標(biāo)簽中使用x:param 標(biāo)簽:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ 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:param 標(biāo)簽</title>
</head>
<body>
<h2>Books Info:</h2>
<c:set var="xmltext">
<books>
<book>
<name>Padam History</name>
<author>ZARA</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>運(yùn)行結(jié)果如下:
