<x:transform>标签在XML文档中应用XSL。
属性
<x:transform>标签有如下属性:
| 属性 | 描述 | 是否必要 | 默认值 |
|---|---|---|---|
| doc | 源XML文档 | 否 | Body |
| docSystemId | 源XML文档的URI | 否 | 无 |
| xslt | XSLT 样式表 | 是 | 无 |
| xsltSystemId | 源XSLT文档的URI | 否 | 无 |
| result | 接收转换结果的对象 | 否 | Print to page |
| var | 代表被转换的XML文档的变量 | 否 | Print to page |
| scope | var属性的作用域 | 否 | 无 |
实例演示
style.xsl文件:
<?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:template match="/"> <HTML> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="books"> <table border="1" width="100%"> <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>
main.jsp文件代码如下:
<%@ 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 标签</title>
</head>
<body>
<h3>Books Info:</h3>
<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}"/>
</body>
</html>
运行结果如下:
