Java Tutorial/JSTL/XML
Содержание
Import XML Data using JSTL
<source lang="java">
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %><%@ taglib uri="http://java.sun.ru/jstl/xml" prefix="x" %> <c:import var="xml" url="students.xml" /> <c:import var="xslt" url="transform.xsl" /> <x:transform xml="${xml}" xslt="${xslt}" /></source>
Output with/without Encode
<source lang="java">
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <html>
<head> <title>Out with Tag Escaping Examples</title> </head> <body> <c:set var="test" scope="page">
</c:set>
Out With Encode=true
<c:out value="${test}" escapeXml="true" />
Out With Encode=false
<c:out value="${test}" escapeXml="false" />
</body>
</html></source>
Set XML Data in JSP Page with JSTL
<source lang="java">
<%@taglib prefix="c" uri="http://java.sun.ru/jstl/core" %> <%@taglib prefix="x" uri="http://java.sun.ru/jstl/xml" %> <c:set var="xml">
<paragraph> This document uses <bold>unusual</bold> markup, which we want to replace with <bold>HTML</bold>. </paragraph>
</c:set> <c:set var="xsl">
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="paragraph">
<xsl:apply-templates/>
</xsl:template> <xsl:template match="bold"> <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet>
</c:set> <x:transform xml="${xml}" xslt="${xsl}"/></source>
Use Table to Display XML Data by JSTL
<source lang="java">
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %><%@ taglib uri="http://java.sun.ru/jstl/xml" prefix="x" %> <html>
<head> <title>For Each Examples</title> </head> <body> <c:import var="students" url="students.xml" /> <x:parse var="doc" xml="${students}" />
First | Last | Points | Letter |
---|---|---|---|
<x:out select="name/first" /> |
<x:out select="name/last" /> |
<x:out select="grade/points" /> |
<x:out select="grade/letter" /> |
</body>
</html></source>