使用样式表格式化获得的XML数据,这个如果使用单独一个XML文件是完全可以的,在XML文件里面嵌入SXL文件,但是现在不要这么作,直接获取XML数据,然后调用XSL文件格式化数据。
        这部分演示程序需要使用到AJAX客户端框架,如下例子所示:
1.ceshi.jsp

获取XML数据并使用样式表格式化<%@ page contentType="text/html;charset=GBK"%>
获取XML数据并使用样式表格式化
<script language="javascript" src="js\request.js"></script>
获取XML数据并使用样式表格式化
<script language="javascript">
获取XML数据并使用样式表格式化
>

 

2.Vehicles.xml

获取XML数据并使用样式表格式化<?xml version="1.0" encoding="gb2312"?>
获取XML数据并使用样式表格式化
<!--?xml-stylesheet href='Vehicles.xsl' type='text/xsl'?-->
获取XML数据并使用样式表格式化
<vehicles>
获取XML数据并使用样式表格式化   
<vehicle year="1002" make="Land Rover" model="Discovery">
获取XML数据并使用样式表格式化         
<mileage>36500</mileage>
获取XML数据并使用样式表格式化         
<color>black</color>
获取XML数据并使用样式表格式化         
<price>$32999</price>
获取XML数据并使用样式表格式化   
</vehicle>
获取XML数据并使用样式表格式化
</vehicles>

3.Vehicles.xsl

获取XML数据并使用样式表格式化<?xml version="1.0"?>
获取XML数据并使用样式表格式化
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD=xsl">
获取XML数据并使用样式表格式化  
<xsl:template match="/">
获取XML数据并使用样式表格式化     
<html>
获取XML数据并使用样式表格式化       
<head>
获取XML数据并使用样式表格式化          
<title>uuu</title>
获取XML数据并使用样式表格式化       
</head>
获取XML数据并使用样式表格式化       
<body>
获取XML数据并使用样式表格式化          
<table align="center" border="2">
获取XML数据并使用样式表格式化          
<tr>
获取XML数据并使用样式表格式化            
<th>Year</th>
获取XML数据并使用样式表格式化            
<th>Make</th>
获取XML数据并使用样式表格式化            
<th>Model</th>
获取XML数据并使用样式表格式化            
<th>Mileage</th>
获取XML数据并使用样式表格式化            
<th>Color</th>
获取XML数据并使用样式表格式化            
<th>Price</th>
获取XML数据并使用样式表格式化          
</tr>
获取XML数据并使用样式表格式化          
<xsl:for-each order-by="+price" select="vehicles/vehicle">
获取XML数据并使用样式表格式化            
<tr>
获取XML数据并使用样式表格式化              
<td><xsl:value-of select="@year"/></td>
获取XML数据并使用样式表格式化              
<td><xsl:value-of select="@make"/></td>
获取XML数据并使用样式表格式化              
<td><xsl:value-of select="@model"/></td>
获取XML数据并使用样式表格式化              
<td><xsl:value-of select="mileage"/></td>
获取XML数据并使用样式表格式化              
<td><xsl:value-of select="color"/></td>
获取XML数据并使用样式表格式化              
<td><xsl:value-of select="price"/></td>
获取XML数据并使用样式表格式化            
</tr>
获取XML数据并使用样式表格式化          
</xsl:for-each>
获取XML数据并使用样式表格式化          
</table>
获取XML数据并使用样式表格式化       
</body>
获取XML数据并使用样式表格式化     
</html>
获取XML数据并使用样式表格式化  
</xsl:template>
获取XML数据并使用样式表格式化
</xsl:stylesheet>

4.说明
        需要注意的XML加载后,XSL文件的加载,以及 xml.transformNode( xsl ) 方法。

相关文章:

  • 2022-12-23
  • 2021-06-14
  • 2021-10-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2022-02-28
猜你喜欢
  • 2021-11-09
  • 2021-09-06
  • 2021-06-20
  • 2022-12-23
  • 2021-05-03
  • 2022-02-07
相关资源
相似解决方案