XML标签-x:transform
<x:transform>标签在XML文档中用于提供XSL(可扩展样式表语言)转换。它可以基于XSLT脚本转换为XML数据。
<x:transform>标签的语法为:
<x:transform attributes> 内容 </x:transform>
让我们看一个简单的示例:
1 编写book.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="doc"/>
<xsl:template match="/">
<html>
<body>
<h2>Book's detail</h2>
<table border="2">
<tr>
<th align="left">Book Name</th>
<th align="left">Author</th>
<th align="left">Price</th>
</tr>
<xsl:for-each select="books/book">
<tr>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="author"/>
</td>
<td>
<xsl:value-of select="price"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
2 编写book.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<name>Head First Java</name>
<author>Kathy Sierra</author>
<price>40</price>
</book>
<book>
<name>Thinking In Java</name>
<author> Bruce Eckel</author>
<price>50</price>
</book>
<book>
<name>Effective Java</name>
<author>Joshua Bloch</author>
<price>60</price>
</book>
</books>
3 编写index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ 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>一点教程网-标签示例</title>
</head>
<body>
<c:import var="xml" url="http://localhost:8080/book.xml" />
<c:import var="xsl" url="http://localhost:8080/book.xsl" />
<x:transform xml="${xml}" xslt="${xsl}"/>
</body>
</html>
4 运行测试
热门文章
优秀文章