中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

Jsp結(jié)合XML+XSLT將輸出轉(zhuǎn)換為Html格式

 我們知道 XML+XSLT就可以直接輸出到支持XML的瀏覽器上,如IE 5.0以上,但是,我們還要考慮到有不少瀏覽器不直接支持XML,在這種情況下,我們需要在服務(wù)器上進(jìn)行轉(zhuǎn)換成html輸出到瀏覽器,這種臨時(shí)過渡辦法恐怕要在一段時(shí)間內(nèi)一直要使用.   使用Jsp 加上tablib標(biāo)識(shí)庫,我們可以完成這種轉(zhuǎn)換。

  著名open source項(xiàng)目組jakarta.apache.org推出的系列標(biāo)識(shí)庫中,就有這個(gè)功能的tanglib:http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html

  按照jakarta配置方法,有點(diǎn)繁瑣,需要修改或定義Web.xml,本人經(jīng)過摸索,使用下列相當(dāng)簡單的辦法,就可以使Jsp能成功運(yùn)行XSL這個(gè)標(biāo)識(shí)庫了。

  xsl標(biāo)識(shí)庫有三個(gè)關(guān)鍵包:
   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.將這三個(gè)包放置到Tomcat的common/lib目錄下,或者直接放入Classpath環(huán)境中。

  2.在JSP中調(diào)用標(biāo)識(shí)庫:

  原來Jakarta推薦方法是:


<%@taglib 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>

  這種做法雖然很標(biāo)準(zhǔn),但是,如果你的容器一直使用tomcat,就完全不必了。

  我們的做法是:


<%@taglib uri="xsl.jar" prefix="xsl" %> 

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

  Apply.jsp


<%@taglib uri="xsl.jar" prefix="xsl" %>
<html>
<head>
<title>Employee List</title>
</head>
<body bgcolor="white">

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

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


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


<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>下面使使用include調(diào)用的辦法,這樣一個(gè)XSLT樣式可以適應(yīng)不同的XML文件。

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

<p>下面是使用import方法,在page-scope(類似scope="page")中導(dǎo)入XML文件</p>

<xsl:import id="data" page="/xml/employees.xml"/>
<xsl:apply nameXml="data" xsl="/xml/employeeList.xsl"/>

</body>
 

  在上面程序中,展示了四種Jsp組合XML XSLT的方法,基本可以滿足我們的需要。注意上面的XML文件路徑是"/xml/",這是相對Tomcat容器的絕對路徑。

  我們簡單看一下employeeList.xsl和employees.xml內(nèi)容:

  employeeList.xsl類似html中的CSS,主要是對XML中數(shù)據(jù)顯示方式進(jìn)行定義:

<?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>

 

employees.xml

<?xml version="1.0" encoding="ISO-8859-1"?>


<employees>
 <employee id="123">
 ?。糵irst-name>John</first-name>
 ?。糽ast-name>Doe</last-name>
 ?。紅elephone>800-555-1212</telephone>
?。?employee>

?。糴mployee id="456">
 ?。糵irst-name>Jane</first-name>
  <last-name>Smith</last-name>
  <telephone>888-555-1212</telephone>
 </employee>

  <employee id="789">
 ?。糵irst-name>George</first-name>
 ?。糽ast-name>Taylor</last-name>
 ?。紅elephone>555-555-1212</telephone>
?。?employee>
</employees>
 

  如果我們在employees.xml頂部加入:


<?xml:stylesheet type="text/xsl" href="catalog.xsl"?> 

  用支持XML的IE 5.0以上瀏覽器調(diào)用,其顯示頁面就和Apply.jsp顯示頁面是一樣的。


 

jsp技術(shù)Jsp結(jié)合XML+XSLT將輸出轉(zhuǎn)換為Html格式,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产精品一区二区免费 | 国产一区二区三区色淫影院 | 久久亚洲一区二区三区四区 | 国产精品国产三级国产aⅴ原创 | 91久久精| 色必久久| 国产午夜在线观看 | 欧美综合一区二区 | 日韩视频精品 | 欧美视频免费在线 | 啪视频在线 | 情侣酒店偷拍一区二区在线播放 | 97国产在线视频 | 国产一区www| 亚洲精品视频一区二区三区 | 一区二区三区四区毛片 | 亚洲色欲色欲www | 黄色片在线看 | 国产69精品久久99不卡免费版 | 国产99精品| 岛国精品 | 操操操日日日 | 色综合色综合色综合 | 免费毛片网站在线观看 | 日韩中文一区 | 精品不卡 | 日韩中文字幕在线视频 | 久久av资源网 | 黄色大片在线视频 | 精品国产一区二区三区性色av | 日韩国产在线 | 日本人做爰大片免费观看一老师 | 中文成人在线 | 国产中文视频 | 欧美一区视频 | 国产成人av一区二区三区 | 国产精品久久久久久久久久久新郎 | 免费观看黄色一级片 | 97国产精品视频人人做人人爱 | 天天噜天天干 | 福利视频二区 |