日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > web前端 > htmlcss > JSP結(jié)合XML+XSLT將輸出轉(zhuǎn)換HTML

JSP結(jié)合XML+XSLT將輸出轉(zhuǎn)換HTML

來源:程序員人生   發(fā)布時(shí)間:2013-10-17 03:32:34 閱讀次數(shù):2706次
我們知道 XML+XSLT就可以直接輸出到支持XML的瀏覽器上,如IE 5.0以上,但是,我們還要考慮到有不少瀏覽器不直接支持XML,在這種情況下,我們需要在服務(wù)器上進(jìn)行轉(zhuǎn)換成html輸出到瀏覽器,這種臨時(shí)過渡辦法恐怕要在一段時(shí)間內(nèi)一直要使用. bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  使用Jsp 加上tablib標(biāo)識(shí)庫(kù),我們可以完成這種轉(zhuǎn)換。bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  著名open source項(xiàng)目組jakarta.apache.org推出的系列標(biāo)識(shí)庫(kù)中,就有這個(gè)功能的tanglib:http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.htmlbhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  按照jakarta配置方法,有點(diǎn)繁瑣,需要修改或定義Web.xml,本人經(jīng)過摸索,使用下列相當(dāng)簡(jiǎn)單的辦法,就可以使Jsp能成功運(yùn)行XSL這個(gè)標(biāo)識(shí)庫(kù)了。bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  xsl標(biāo)識(shí)庫(kù)有三個(gè)關(guān)鍵包:bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  xerces.jar 可以在http://xml.apache.org/中得到 bhd站長(zhǎng)資訊
  xalan.jar 可以在http://xml.apache.org/中得到 bhd站長(zhǎng)資訊
  xsl.jar 從http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html得到bhd站長(zhǎng)資訊
  1.將這三個(gè)包放置到Tomcat的common/lib目錄下,或者直接放入Classpath環(huán)境中。bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  2.在JSP中調(diào)用標(biāo)識(shí)庫(kù):bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  原來Jakarta推薦方法是:bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<%@taglib uri="http://jakarta.apache.org/taglibs/xsl-1.0" prefix="xsl" %> bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  這就需要在/WEB-INF/web.xml下定義一下http://jakarta.apache.org/taglibs/xsl-1.0指向。如:bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<taglib> bhd站長(zhǎng)資訊
<taglib-uri>http://jakarta.apache.org/taglibs/xsl-1.0</taglib-uri> bhd站長(zhǎng)資訊
<taglib-location>/WEB-INF/xsl.tld</taglib-location> bhd站長(zhǎng)資訊
</taglib> bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  這種做法雖然很標(biāo)準(zhǔn),但是,如果你的容器一直使用tomcat,就完全不必了。bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  我們的做法是:bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<%@taglib uri="xsl.jar" prefix="xsl" %> bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  我們以Jakarta的XSL taglib附帶的Apply.jsp為例,正好了解一下Jsp XML XSLT三者之間的關(guān)系:bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  Apply.jspbhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<%@taglib uri="xsl.jar" prefix="xsl" %> bhd站長(zhǎng)資訊
<html>bhd站長(zhǎng)資訊
<head>bhd站長(zhǎng)資訊
<title>Employee List</title>bhd站長(zhǎng)資訊
</head>bhd站長(zhǎng)資訊
<body bgcolor="white">bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<p>下面展示了Jsp的四種組合XML XSLT的方法:bhd站長(zhǎng)資訊
<p>下面使用apply方法,將已經(jīng)存在的employees.xml和employeeList.xsl結(jié)合在一起bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<xsl:apply xml="/xml/employees.xml" xsl="/xml/employeeList.xsl"/>bhd站長(zhǎng)資訊
<hr>bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<p>下面是使用已經(jīng)存在employeeList.xsl 然后在Jsp中自己直接寫入XML數(shù)據(jù).bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<xsl:apply xsl="/xml/employeeList.xsl">bhd站長(zhǎng)資訊
<?xml version="1.0" encoding="ISO-8859-1"?>bhd站長(zhǎng)資訊
<employees>bhd站長(zhǎng)資訊
<employee id="123">bhd站長(zhǎng)資訊
<first-name>John</first-name>bhd站長(zhǎng)資訊
<last-name>Doe</last-name>bhd站長(zhǎng)資訊
<telephone>800-555-1212</telephone>bhd站長(zhǎng)資訊
</employee>bhd站長(zhǎng)資訊
<employee id="456">bhd站長(zhǎng)資訊
<first-name>Jane</first-name>bhd站長(zhǎng)資訊
<last-name>Smith</last-name>bhd站長(zhǎng)資訊
<telephone>888-555-1212</telephone>bhd站長(zhǎng)資訊
</employee>bhd站長(zhǎng)資訊
<employee id="789">bhd站長(zhǎng)資訊
<first-name>George</first-name>bhd站長(zhǎng)資訊
<last-name>Taylor</last-name>bhd站長(zhǎng)資訊
<telephone>555-555-1212</telephone>bhd站長(zhǎng)資訊
</employee>bhd站長(zhǎng)資訊
</employees>bhd站長(zhǎng)資訊
</xsl:apply>bhd站長(zhǎng)資訊
<hr>bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<p>下面使使用include調(diào)用的辦法,這樣一個(gè)XSLT樣式可以適應(yīng)不同的XML文件。bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<xsl:apply xsl="/xml/employeeList.xsl">bhd站長(zhǎng)資訊
<xsl:include page="/xml/employees.xml"/>bhd站長(zhǎng)資訊
</xsl:apply>bhd站長(zhǎng)資訊
<hr>bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<p>下面是使用import方法,在page-scope(類似scope="page")中導(dǎo)入XML文件</p>bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<xsl:import id="data" page="/xml/employees.xml"/>bhd站長(zhǎng)資訊
<xsl:apply nameXml="data" xsl="/xml/employeeList.xsl"/>bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
</body>bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
在上面程序中,展示了四種Jsp組合XML XSLT的方法,基本可以滿足我們的需要。注意上面的XML文件路徑是"/xml/",這是相對(duì)Tomcat容器的絕對(duì)路徑。 bhd站長(zhǎng)資訊
  我們簡(jiǎn)單看一下employeeList.xsl和employees.xml內(nèi)容:bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  employeeList.xsl類似html中的CSS,主要是對(duì)XML中數(shù)據(jù)顯示方式進(jìn)行定義:bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<?xml version="1.0"?> bhd站長(zhǎng)資訊
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> bhd站長(zhǎng)資訊
<xsl:template match="employees">bhd站長(zhǎng)資訊
<table border="1" width="100%">bhd站長(zhǎng)資訊
<tr>bhd站長(zhǎng)資訊
<th>ID</th>bhd站長(zhǎng)資訊
<th>Employee Name</th>bhd站長(zhǎng)資訊
<th>Phone Number</th>bhd站長(zhǎng)資訊
</tr>bhd站長(zhǎng)資訊
<xsl:for-each select="employee">bhd站長(zhǎng)資訊
<tr>bhd站長(zhǎng)資訊
<td>bhd站長(zhǎng)資訊
<xsl:value-of select="@id"/>bhd站長(zhǎng)資訊
</td>bhd站長(zhǎng)資訊
<td>bhd站長(zhǎng)資訊
<xsl:value-of select="last-name"/>, bhd站長(zhǎng)資訊
<xsl:value-of select="first-name"/>bhd站長(zhǎng)資訊
</td>bhd站長(zhǎng)資訊
<td>bhd站長(zhǎng)資訊
<xsl:value-of select="telephone"/>bhd站長(zhǎng)資訊
</td>bhd站長(zhǎng)資訊
</tr>bhd站長(zhǎng)資訊
</xsl:for-each>bhd站長(zhǎng)資訊
</table>bhd站長(zhǎng)資訊
</xsl:template>bhd站長(zhǎng)資訊
</xsl:stylesheet> bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  employees.xml bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<?xml version="1.0" encoding="ISO-8859-1"?> bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<employees> bhd站長(zhǎng)資訊
 <employee id="123"> bhd站長(zhǎng)資訊
  <first-name>John</first-name> bhd站長(zhǎng)資訊
  <last-name>Doe</last-name> bhd站長(zhǎng)資訊
  <telephone>800-555-1212</telephone> bhd站長(zhǎng)資訊
 </employee> bhd站長(zhǎng)資訊
 <employee id="456"> bhd站長(zhǎng)資訊
  <first-name>Jane</first-name> bhd站長(zhǎng)資訊
  <last-name>Smith</last-name> bhd站長(zhǎng)資訊
  <telephone>888-555-1212</telephone> bhd站長(zhǎng)資訊
 </employee> bhd站長(zhǎng)資訊
  <employee id="789"> bhd站長(zhǎng)資訊
  <first-name>George</first-name> bhd站長(zhǎng)資訊
  <last-name>Taylor</last-name> bhd站長(zhǎng)資訊
  <telephone>555-555-1212</telephone> bhd站長(zhǎng)資訊
 </employee> bhd站長(zhǎng)資訊
</employees> bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  如果我們?cè)趀mployees.xml頂部加入:bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
<?xml:stylesheet type="text/xsl" href="catalog.xsl"?> bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
bhd站長(zhǎng)資訊
  用支持XML的IE 5.0以上瀏覽器調(diào)用,其顯示頁(yè)面就和Apply.jsp顯示頁(yè)面是一樣的。
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 日韩在线精品视频 | 在线观看av一区 | 国产成人毛片 | 亚洲欧美一区二区三区 | 日韩免费视频一区二区 | 国产精品久久久久久久久久久久午夜片 | 福利视频一二三在线视频免费观看 | 国产精品久久久久久久岛一牛影视 | 欧美日韩一区二区三区 | 欧美激情网站 | 久久性片 | 国产一区二区视频在线观看免费 | 嫩草网址 | 男女污视频 | 乱码av | 久久久久久免费精品一区二区三区 | 日韩电影免费在线观看 | 国内在线视频 | 国产iv一区二区三区 | 成人国产一区 | 日韩精品第一区 | 成年人视频免费在线观看 | 日韩免费在线观看 | av在线一区二区三区四区 | 91精品国产一区 | 中文字幕国产亚洲 | 国产免费区一区二区三视频免费 | 9999精品| 国产一区二区三区观看 | 成人av网站在线 | 久久国产成人精品 | 成年人免费在线观看 | 91精品国产综合久久久久 | 99国产精品久久久久久久成人热 | 一区二区三区四区在线播放 | 在线视频这里只有精品 | 国产精品99精品久久免费 | 日韩欧美电影在线观看 | 91精品国产91久久综合桃花 | 日日操夜夜操狠狠操 | av中文字幕在线观看 |