国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

Jsp,結合XML+XSLT將輸出轉換為Html格式

2019-11-02 15:47:37
字體:
來源:轉載
供稿:網友

 

 我們知道 xml+XSLT就可以直接輸出到支持XML的瀏覽器上,如IE 5.0以上,但是,我們還要考慮到有不少瀏覽器不直接支持XML,在這種情況下,我們需要在服務器上進行轉換成html輸出到瀏覽器,這種臨時過渡辦法恐怕要在一段時間內一直要使用.   使用jsp 加上tablib標識庫,我們可以完成這種轉換。

  著名open source項目組jakarta.apache.org推出的系列標識庫中,就有這個功能的tanglib:http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html

  按照jakarta配置方法,有點繁瑣,需要修改或定義Web.xml,本人經過摸索,使用下列相當簡單的辦法,就可以使Jsp能成功運行XSL這個標識庫了。

  xsl標識庫有三個關鍵包:
xerces.jar 可以在http://xml.apache.org/中得到
xalan.jar 可以在http://xml.apache.org/中得到
xsl.jar 從http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html得到

  1.將這三個包放置到Tomcat的common/lib目錄下,或者直接放入Classpath環境中。

  2.在JSP中調用標識庫:

  原來Jakarta推薦方法是:


<[email protected] uri="http://jakarta.apache.org/taglibs/xsl-1.0" PRefix="xsl" %>

  這就需要在/WEB-INF/web.xml下定義一下http://jakarta.apache.org/taglibs/xsl-1.0指向。如:


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

  這種做法雖然很標準,但是,如果你的容器一直使用tomcat,就完全不必了。

  我們的做法是:


<[email protected] uri="xsl.jar" prefix="xsl" %> 

  我們以Jakarta的XSL taglib附帶的Apply.jsp為例,正好了解一下Jsp XML XSLT三者之間的關系:

  Apply.jsp


<[email protected] uri="xsl.jar" prefix="xsl" %>
<html>
<head>
<title>Employee List</title>
</head>
<body bgcolor="white">

<p>下面展示了Jsp的四種組合XML XSLT的方法:
<p>下面使用apply方法,將已經存在的employees.xml和employeeList.xsl結合在一起

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


<p>下面是使用已經存在employeeList.xsl 然后在Jsp中自己直接寫入XML數據.


<xsl:apply xsl="/xml/employeeList.xsl">
<?xml

動漫資源[www.aikan.tv/xzhtml/4/]
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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 视频| 伊宁市| 临颍县| 江城| 宾阳县| 莱阳市| 自贡市| 明水县| 神木县| 黔南| 敦化市| 前郭尔| 顺昌县| 清镇市| 宜君县| 库伦旗| 图们市| 敦煌市| 库车县| 惠水县| 阿尔山市| 宁城县| 璧山县| 东明县| 六安市| 伊宁市| 乌拉特中旗| 黔西| 土默特右旗| 南川市| 望谟县| 巧家县| 娄底市| 青海省| 玉门市| 富裕县| 务川| 霸州市| 永吉县| 丹江口市| 甘南县|