We know that jsp xml xslt can be directly output to browsers that support XML, such as IE 5.0 or later. However, we also need to consider that many Browsers Do not directly support XML. In this case, we need to convert to html output to the browser on the server. I am afraid this temporary transition method will be used for a while.
Using JSP with tablib to identify the library, we can complete this conversion.
The famous open source project team 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
According to the configuration method of jakarta, it is a little complicated. You need to modify or define Web. xml. After self-exploration, you can use the following simple methods to make JSP successfully run the XSL identity 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 can be 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">
The following shows the Jsp xml xslt method:
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>
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>
In the above program, four jsp xml xslt methods are displayed, which can basically meet our needs. Note that the above XML file path is "/xml/", which is the absolute path relative to the Tomcat container.
Let's take a brief look at the content of employeeList. xsl and employees. xml:
EmployeeList. xsl is similar to CSS in html. It mainly defines the data display mode in XML:
- <?xml version="1.0"?>
- <xsl:stylesheet version="1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform">
- <xsl:template match="employees">
- <table border="1" width="100%">
- <tr>
- <th>ID</th>
- <th>Employee Name</th>
- <th>Phone Number</th>
- </tr>
- <xsl:for-each select="employee">
- <tr>
- <td>
- <xsl:value-of select="@id"/>
- </td>
- <td>
- <xsl:value-of select="last-name"/>,
- <xsl:value-of select="first-name"/>
- </td>
- <td>
- <xsl:value-of select="telephone"/>
- </td>
- </tr>
- </xsl:for-each>
- </table>
- </xsl:template>
- </xsl:stylesheet>
- Intrude into JSP website servers
- JSP-Based Network
- JSP variables are called range variables in the specification.
- Summary of ASP advantages and JSP advantages
- Detailed description of custom JSP labels