Servlet与Jsp学习笔记--11、Xml
JSTL Tags
<%@page contentType="text/html" pageEncoding="GB2312"%>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head><title>Using the Core XML tags</title></head>
<body>
<h2>Here are the target and property values from the XML file</h2>
<c:import url="http://localhost:8080/ora/build.xml" var="buildXml" />
<x:parse xml="${buildXml}" var="antDoc" />
<h3>First the target names...</h3>
<x:forEach select="$antDoc/project/target" >
<x:out select="@name"/>
<x:if select="@depends"> : depends=<x:out select="@depends"/></x:if><br />
</x:forEach>
<h3>Then property names and values...</h3>
<x:forEach select="$antDoc/project/target/property" >
<x:out select="@name"/>: value= <x:out select="@value"/><br />
</x:forEach>
<x:parse var="xmlbody">
<customer>
<customerid>2002</customerid>
<customername>tea</customername>
</customer>
</x:parse>
<b><u>解释XML本体内容</u></b><br>
客户编号(customerid):
<x:out select="$xmlbody/customer/customerid"/><br>
客户姓名(customername):
<x:out select="$xmlbody/customer/customername" /><br>
</body>
</html>
XML Transform
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html><head><title>List of build.xml targets
</title></head><body bgcolor="white"><h2>Build.xml targets</h2>
<xsl:apply-templates />
</body></html>
</xsl:template>
<xsl:template match="/project">
<dl>
<xsl:for-each select="./target">
<dt><b>
<xsl:value-of select="@name" /></b> </dt>
<xsl:if test="@depends">
<dd>depends=<xsl:value-of select="@depends" /> </dd>
</xsl:if>
</xsl:for-each><!--end for-each -->
</dl>
</xsl:template>
<xsl:template match="text( )">
<xsl:value-of select="normalize-space( )" />
</xsl:template>
</xsl:stylesheet>
显示:
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<c:import url="http://localhost:8080/home/build.xml" var="buildXml" />
<c:import url="/WEB-INF/xslt/chap23.xsl" var="xslt" />
<x:transform xml="${buildXml}" xslt="${xslt}" />
目前维护的开源产品:https://gitee.com/475660