We know that XML+XSLT can be directly exported to XML-enabled browsers, such as IE more than 5.0, but we also have to consider that there are many browsers do not directly support XML, in this case, we need to convert the server to HTML output to the browser, This interim transitional approach may have to be used for some time. Using JSP plus the Tablib identity Library, we can do this transformation.
The well-known open source project group Jakarta.apache.org launched a series of identity libraries, there is this feature tanglib:http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html
According to the Jakarta configuration method, a bit cumbersome, need to modify or define Web.xml, I after groping, using the following fairly simple method, you can make JSP successfully run XSL this identity library.
The XSL Identity library has three key packages:
Xerces.jar can be obtained in http://xml.apache.org/.
Xalan.jar can be obtained in http://xml.apache.org/.
Xsl.jar get from http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html
1. Place the three packages in the Common/lib directory of Tomcat or directly into the CLASSPATH environment.
2. Call the identity library in the JSP:
The original Jakarta recommended method is:
<% @taglib uri= "http://jakarta.apache.org/taglibs/xsl-1.0" prefix= "xsl"%>
This requires a http://jakarta.apache.org/taglibs/xsl-1.0 point to be defined under/web-inf/web.xml. Such as:
http://jakarta.apache.org/taglibs/xsl-1.0
/web-inf/xsl.tld
This is a standard practice, but if you have a container that uses Tomcat all the time, you don't have to.
Our approach is to:
<% @taglib uri= "Xsl.jar" prefix= "xsl"%>
Let's take the apply.jsp of the Jakarta XSL Taglib as an example, just to understand the relationship between the JSP XML XSLT:
apply.jsp
<% @taglib uri= "Xsl.jar" prefix= "xsl"%>
Employee List
The
shows the following methods for JSP's four combinatorial XML XSLT:
Use the Apply method below to combine existing employees.xml and employeelist.xsl
The following is written directly to XML data in the JSP using an already existing employeelist.xsl.
John
Doe
800-555-1212
Jane
Smith
888-555-1212
George
Taylor
555-555-1212
The following methods are invoked with include, such that an XSLT style can be adapted to different XML files.
The following is to import an XML file in Page-scope (similar to scope= "page") by using the Import method
In the above program, we show four kinds of JSP combined XML XSLT method, basically can meet our needs. Note that the XML file path above is "/xml/", which is the absolute path relative to the Tomcat container.
Let's take a quick look at the employeelist.xsl and employees.xml content:
Employeelist.xsl is similar to CSS in HTML, primarily to define how data is displayed in XML:
>
ID |
Employee Name |
Phone Number |
|
,
|
|
Employees.xml
John
Doe
800-555-1212
Jane
Smith
888-555-1212
George
Taylor
555-555-1212
If we add at the top of the employees.xml:
Called with the XML-enabled IE 5.0 browser, the display page is the same as the apply.jsp display page.