We know that XML + XSLT can be directly output Supported XML browsers, such as IE 5.0 or above, but we also need to consider that many Browsers Do not directly support xml. In this case, we need to convert the file to HTML and output it to the browser on the server. Time Always use.
Using JSP with tablib to identify the library, we can complete this conversion.
Famous Open Source Project Group jakarta.apache.org launched a series of identification library, there is this function of tanglib: http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html
Configure according to Jakarta Method , A little tedious, You need to modify or define web. xml. After exploring, you can use the following simple method to enable JSP Successful Run the XSL identification library.
The XSL identification library has three key packages:
- Xerces. jar can be obtained at http://xml.apache.org/
- Xalan. jar can be obtained at http://xml.apache.org/
- XSL. jar is obtained from http://jakarta.apache.org/taglibs/doc/developer-doc/intro.html
1. Place the three packages in the common/lib directory of Tomcat, or directly put them in the classpath environment.
2. Call the identification library in JSP:
The original recommended methods for Jakarta are:
<% @ Taglib uri = "http://jakarta.apache.org/taglibs/xsl-1.0" prefix = "XSL" %> |
This requires defining http://jakarta.apache.org/taglibs/xsl-1.0in/WEB-INF/Web. xml. For example:
<Taglib> <Taglib-Uri> http://jakarta.apache.org/taglibs/xsl-1.0 </taglib-Uri> <Taglib-location>/WEB-INF/XSL. TLD </taglib-location> </Taglib> |
Although this method is very standard, if your container has been using tomcat, it is completely unnecessary.
Our practice is:
<% @ Taglib uri = "XSL. Jar" prefix = "XSL" %> |
Take apply. jsp with XSL taglib of Jakarta as an example to understand the relationship between jsp xml xslt:
Apply. jsp
<% @ Taglib uri = "XSL. Jar" prefix = "XSL" %> <HTML> <Head> <Title> employee list </title> </Head> <Body bgcolor = "white"> <P> The following shows four methods for combining xml xslt in JSP: <P> the following uses the apply method to combine existing employees. XML with employeelist. XSL. <XSL: Apply xml = "/XML/employees. xml" XSL = "/XML/employeelist. XSL"/> <HR> <P> The following describes how to use employeelist. XSL to directly write XML data in JSP. <XSL: Apply XSL = "/XML/employeelist. XSL"> <? XML version = "1.0" encoding = "ISO-8859-1"?> <Employees> <Employee ID = "123"> <First-name> JOHN </first-name> <Last-name> Doe </last-name> <Telephone> 800-555-1212 </telephone> </Employee> <Employee ID = "456"> <First-name> Jane </first-name> <Last-name> Smith </last-name> <Telephone> 888-555-1212 </telephone> </Employee> <Employee ID = "789"> <First-name> George </first-name> <Last-name> Taylor </last-name> <Telephone> 555-555-1212 </telephone> </Employee> </Employees> </XSL: Apply> <HR> <P> The following describes how to call include. Such An XSLT style can adapt to different XML files. <XSL: Apply XSL = "/XML/employeelist. XSL"> <XSL: Include page = "/XML/employees. xml"/> </XSL: Apply> <HR> <P> The following describes how to import an XML file in page-scope (similar to scope = "page") using the import method. </P> <XSL: Import id = "data" page = "/XML/employees. xml"/> <XSL: Apply namexml = "data" XSL = "/XML/employeelist. XSL"/> </Body> |