| |
24. 32. 1. 使用JSTL导入XML数据 |
|
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %><%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<c:import var="xml" url="students.xml" />
<c:import var="xslt" url="transform.xsl" />
<x:transform xml="${xml}" xslt="${xslt}" />
|
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<students>
<student id="1">
<name>
<first>A</first>
<last>B</last>
<middle>T</middle>
</name>
<grade>
<points>88</points>
<letter>B</letter>
</grade>
</student>
<student id="2">
<name>
<first>C</first>
<last>D</last>
<middle>K</middle>
</name>
<grade>
<points>92</points>
<letter>A</letter>
</grade>
</student>
<student id="3">
<name>
<first>E</first>
<last>F</last>
<middle>A</middle>
</name>
<grade>
<points>72</points>
<letter>C</letter>
</grade>
</student>
</students>
|
|
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="students">
<html>
<head>
<title>XSLT Transform</title>
</head>
<body>
<table border="1">
<tr><TH>First</th><TH>Last</th><TH>Points</th><TH>Letter</th></tr>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="student">
<tr>
<td><xsl:value-of select="name/first"/></td>
<td><xsl:value-of select="name/last"/></td>
<td><xsl:value-of select="grade/points"/></td>
<td><xsl:value-of select="grade/letter"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
|
|
Download: JSTLImportXMLData.zip( 1,560 k) |
|