Jsp xml xslt converts output to HTML

Source: Internet
Author: User

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:

 
 
  1. <%@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:

 
 
  1. <taglib>  
  2. <taglib-uri>http://jakarta.apache.org/taglibs/xsl-1.0</taglib-uri>  
  3. <taglib-location>/WEB-INF/xsl.tld</taglib-location>  
  4. </taglib> 

Although this method is very standard, if your container has been using tomcat, it is completely unnecessary.

Our practice is:

 
 
  1. <%@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

 
 
  1. <%@taglib uri="xsl.jar" prefix="xsl" %>  
  2. <html>  
  3. <head>  
  4. <title>Employee List</title>  
  5. </head>  
  6. <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.

 
 
  1. <xsl:apply xml="/xml/employees.xml" xsl="/xml/employeeList.xsl"/>  
  2. <hr> 

The following describes how to use employeeList. xsl to directly write XML data in Jsp.

 
 
  1. <xsl:apply xsl="/xml/employeeList.xsl">  
  2. <?xml version="1.0" encoding="ISO-8859-1"?>  
  3. <employees>  
  4. <employee id="123">  
  5. <first-name>John</first-name>  
  6. <last-name>Doe</last-name>  
  7. <telephone>800-555-1212</telephone>  
  8. </employee>  
  9. <employee id="456">  
  10. <first-name>Jane</first-name>  
  11. <last-name>Smith</last-name>  
  12. <telephone>888-555-1212</telephone>  
  13. </employee>  
  14. <employee id="789">  
  15. <first-name>George</first-name>  
  16. <last-name>Taylor</last-name>  
  17. <telephone>555-555-1212</telephone>  
  18. </employee>  
  19. </employees>  
  20. </xsl:apply>  
  21. <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:

 
 
  1. <?xml version="1.0"?>  
  2. <xsl:stylesheet version="1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform">  
  3. <xsl:template match="employees">  
  4. <table border="1" width="100%">  
  5. <tr>  
  6. <th>ID</th>  
  7. <th>Employee Name</th>  
  8. <th>Phone Number</th>  
  9. </tr>  
  10. <xsl:for-each select="employee">  
  11. <tr>  
  12. <td>  
  13. <xsl:value-of select="@id"/>  
  14. </td>  
  15. <td>  
  16. <xsl:value-of select="last-name"/>,  
  17. <xsl:value-of select="first-name"/>  
  18. </td>  
  19. <td>  
  20. <xsl:value-of select="telephone"/>  
  21. </td>  
  22. </tr>  
  23. </xsl:for-each>  
  24. </table>  
  25. </xsl:template>  
  26. </xsl:stylesheet>  
  1. Intrude into JSP website servers
  2. JSP-Based Network
  3. JSP variables are called range variables in the specification.
  4. Summary of ASP advantages and JSP advantages
  5. Detailed description of custom JSP labels

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.