XSLT专业站 - 提供xslt和xml相关的资料书籍和教程  
XSLT专业站 - 提供xslt和xml相关的资料书籍和教程
网站地图  收藏本站
首页 | 热门文章 | 精彩实例 | 经典教程 | XSLT语法详解 | 资料下载 | 休闲天地 | 交流论坛
  当前位置:首页>热门文章>XSLT>文章内容
JSP结合XML+XSLT将输出转换HTML
来源:XSLT.org.cn 作者:XSLT专业站 发布时间:2007-08-04  
JSP结合XML+XSLT将输出转换HTML


  在上面程序中,展示了四种Jsp组合XML XSLT的方法,基本可以满足我们的需要。注意上面的XML文件路径是"/xml/",这是相对Tomcat容器的绝对路径。

  我们简单看一下employeeList.xsl和employees.xml内容:

  employeeList.xsl类似html中的CSS,主要是对XML中数据显示方式进行定义:

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

  如果我们在employees.xml顶部加入:

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

  用支持XML的IE 5.0以上浏览器调用,其显示页面就和Apply.jsp显示页面是一样的。

 



标题: JSP结合XML+XSLT将输出转换HTML
关键字:转换 XML xsl xslt
共2页: 上一页 [1] 2 下一页
上一篇:使用 Java 和 XSLT 生成动态 Web页面   下一篇:XSL 函数介绍(1)
  XSLT热点文章
·从 XSLT 样式表调用 JavaScript
·使用 XSLT 转换属性
·用节点集计数
·使用 XSLT 进行断行
·使用 Java 和 XSLT 生成动态 Web
  XSLT相关文章
·使用 Java 和 XSLT 生成动态 Web
·使用 XSLT 进行断行
·从 XSLT 样式表调用 JavaScript
·用节点集计数
·使用 XSLT 转换属性
Copyright© 2007 xslt.org.cn All rights reserved.