<x:transform> 标签


<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文件:

  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl=
  3. "http://www.w3.org/1999/XSL/Transform" version="1.0">
  4.  
  5. <xsl:output method="html" indent="yes"/>
  6.  
  7. <xsl:template match="/">
  8. <html>
  9. <body>
  10. <xsl:apply-templates/>
  11. </body>
  12. </html>
  13. </xsl:template>
  14.  
  15. <xsl:template match="books">
  16. <table border="1" width="100%">
  17. <xsl:for-each select="book">
  18. <tr>
  19. <td>
  20. <i><xsl:value-of select="name"/></i>
  21. </td>
  22. <td>
  23. <xsl:value-of select="author"/>
  24. </td>
  25. <td>
  26. <xsl:value-of select="price"/>
  27. </td>
  28. </tr>
  29. </xsl:for-each>
  30. </table>
  31. </xsl:template>

main.jsp文件代码如下:

  1. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  2. <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
  3.  
  4. <html>
  5. <head>
  6. <title>JSTL x:transform 标签</title>
  7. </head>
  8. <body>
  9. <h3>Books Info:</h3>
  10. <c:set var="xmltext">
  11. <books>
  12. <book>
  13. <name>Padam History</name>
  14. <author>ZARA</author>
  15. <price>100</price>
  16. </book>
  17. <book>
  18. <name>Great Mistry</name>
  19. <author>NUHA</author>
  20. <price>2000</price>
  21. </book>
  22. </books>
  23. </c:set>
  24.  
  25. <c:import url="http://localhost:8080/style.xsl" var="xslt"/>
  26. <x:transform xml="${xmltext}" xslt="${xslt}"/>
  27.  
  28. </body>
  29. </html>

运行结果如下:

x-transform