<X:变换>标记适用于一个XML文档XSL转换。
<X:变换>标签具有以下属性-
| 属性 | 描述 | 需要 | 默认 | 
|---|---|---|---|
| doc | XSLT转换的源XML文档 | 没有 | 身体 | 
| docSystemId | 原始XML文档的URI | 没有 | 没有 | 
| xslt | XSLT样式表提供转换说明 | 是 | 没有 | 
| xsltSystemId | 原始XSLT文档的URI | 没有 | 没有 | 
| 结果 | 结果对象接受转换的结果 | 没有 | 打印到页面 | 
| 变种 | 设置为转换后的XML文档的变量 | 没有 | 打印到页面 | 
| 范围 | 暴露转换结果的变量范围 | 没有 | 没有 | 
请看下面的XSLT样式表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> </xsl:stylesheet>
现在请看以下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 Tags</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>您将收到以下结果-
| Padam历史 ZARA | 100 | 
| 大 薄雾NUHA | 2000 |