Jstl_xml
One: Description
- If there is reprint please indicate the source
- Properties that must contain properties, including default values, are separated by a carriage return
Two: XML tag library
The main function of XML tag library is to facilitate the operation of XML in JSP pages, this blog does not do a detailed explanation, <x:out>,<x:set>,<x:if>,<x:when>,<x:choose The >,<x:forEach>,<x:otherwise>,<x:param> tag is basically the same as the tag in the core tag library, the only difference being that these tokens are the ones that handle the XML content.
Three: XML tags
1. <x:out>,<x:set>,<x:if>,<x:when>,<x:choose>,<x:foreach>,<x:otherwise The >,<x:param> tag is basically the same as the tag in the core tag library, the only difference being that these tokens are the ones that handle the XML content.
2. <x:parse> Mark
Sample code: XML File contents:
<?xml version= "1.0" encoding= "UTF-8"?> <peoples> <people> <name> Darren Brown </name > <sex>man</sex> </people> <people> <name> Everton g</name> <sex>little man</sex> </people> <people> <name> Charlotte Lingling </name > <sex>women</sex> </people> <people> <name> Houston • Magician </ name> <sex>bigman</sex> </people></peoples>
Peoples.xml
JSP file Contents:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "UTF-8"%><%@ taglib uri= "Http://java.sun.com/jsp/jstl/xml" prefix= "x"%><%@ taglib uri= "/http Java.sun.com/jsp/jstl/core "prefix=" C "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >Importvar= "File" url= "Peoples.xml" charencoding= "Utf-8"/> <x:parse xml= "${file}" var= "CC"/> <table border= "1" > <tr> <td> name </td> <td> sex </td> </tr> <x:foreach var= "n" sel ect= "$CC/peoples/people" > <tr> <td> <x:out select= "$n/name"/> </td> <td> <x:out select= "$n/sex"/> </td> & lt;/tr> </x:forEach> </table> </body>xparse.jsp
All properties: Doc: The name of the XML file to parse, or an object of type Java.io.Reader scope: Sets the scope of the VAR variable, default: page scopedom: Set the scope of the Vardom variable, default: Page var: sets the name of the variable that holds the content of the parsed XML document Vardom: Sets the variable name of the object that represents the org.w3c.dom.Document type of the parsed XML file filter: Sets an object of type Org.xml.sax.XMLFilter that can filter the file before parsing systemid: Sets the URI value of the XML file that is currently being parsed
3.<x:transform>
Transformation of XSL style sheets can be implemented
Example code:
<?xml version= "1.0" encoding= "UTF-8"? ><xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL /transform "> <xsl:template match="/"> <!--todo:auto-generated template---- for-each select= "Peoples/people" > <tr> <td><xsl:value-of select= "name"/></td> <td><xsl:value-of select= "Sex"/></ td> </tr> </xsl:for-each> </table></body>
people.xsl<?xml version= "1.0" encoding= "UTF-8"?> <peoples> <people> <name> Darren Brown </name > <sex>man</sex> </people> <people> <name> Everton g</name> <sex>little man</sex> </people> <people> <name> Charlotte Lingling </name > <sex>women</sex> </people> <people> <name> Houston • Magician </ name> <sex>bigman</sex> </people></peoples>
Peoples.xml
transform.jsp
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 " pageencoding=" UTF-8 "%><%@ taglib uri=" Http://java.sun.com/jsp/jstl/core "prefix = "C"%><%@ taglib uri= "Http://java.sun.com/jsp/jstl/xml" prefix= "x"%> <c:import url= " Peoples.xml "var=" url "charencoding=" Utf-8 "/><c:import url=" people.xsl "var=" xsl "charencoding=" Utf-8 "/> <x:transform doc=" ${url} "xslt= " ${xsl} "/>
Description: Doc: The name of the XML file to be converted, or the Java.io.Reader object XSLT: The name of the XSLT file to be converted, or the object of reader or Javax.xml.transform.Source type scope : Set the save scope of the VAR variable, default: page Docsystemid: Sets the URI value of the XML file that is currently being converted Xsltsystemid: Sets the URI value of the XSLT file to convert var: sets the name of the variable after the Save content result: Object that sets the variable of the saved content, object type: Javax.xml.transform.Result
Jstl_xml Tag Library