XML的显示--XSL

XSL包含3部分内容:
1.XSLT:是一种把XML转换为HTML的语言。
2.XPath:是一种定义XML节点路径的语言。
3.XSL Formatting Objects(XSL格式化对象):定义XML显示的语言。
XSLT是通过把XML的每一个元素逐个的转换为HTML元素或代码片段的方法来显示XML文档的。
在转换的同时可以对XML文档添加和删除元素、添加和删除属性、对元素进行重新排列或排序、隐藏或显示某些元素、查找或选择特定元素的操作。
XSL文档本身也是一个XML文件,XSL的根元素:<xsl:stylesheet>或<xsl:transform>
booklist.xsl 如下:
 
<? xml version="1.0" encoding="UTF-8" ?>
< xsl:stylesheet  version ="1.0"  xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" >
< xsl:template  match ="/" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< meta  http_equiv ="Content-Type"  content ="text/html; charset=UTF-8" />
< body >
< center >
    
< table  border ="1"  width ="500px" >
    
< tr >
        
< td > name </ td >
        
< td > price </ td >
        
< td > description </ td >
        
< td > publisher </ td >
    
</ tr >
    
< xsl:for-each  select ="booklist/book" >
    
< tr >
        
< td >< xsl:value-of  select ="name" ></ xsl:value-of ></ td >
        
< td >< xsl:value-of  select ="price" ></ xsl:value-of ></ td >
        
< td >< xsl:value-of  select ="description" ></ xsl:value-of ></ td >
        
< td >< xsl:value-of  select ="publisher" ></ xsl:value-of ></ td >
    
</ tr >
    
</ xsl:for-each >
    
</ table >
</ center >
</ body >
</ html >
</ xsl:template >
</ xsl:stylesheet >
booklist.xml:
<? xml version="1.0" encoding="UTF-8" ?>
<! DOCTYPE booklist [
<!ENTITY publisher "ABC company"
>
]>
<? xml-stylesheet type="text/xsl" href="booklist.xsl" ?>
< booklist >
< book >
< name > Ajax </ name >
< price > $5.95 </ price >
< description > Foundations of Ajax. </ description >
< publisher > &publisher; </ publisher >
</ book >
< book >
< name > Ajax Patterns </ name >
< price > $7.95 </ price >
< description > Introduction of Ajax Patterns. </ description >
< publisher > &publisher; </ publisher >
</ book >
< book >
< name > Ajax Web App </ name >
< price > $8.95 </ price >
< description > Edition 2. </ description >
< publisher > &publisher; </ publisher >
</ book >
< book >
< name > Core CSS </ name >
< price > $4.50 </ price >
< description > A book for CSS. </ description >
< publisher > &publisher; </ publisher >
</ book >
< book >
< name > JSF and Ajax </ name >
< price > $6.95 </ price >
< description > Apress. </ description >
< publisher > &publisher; </ publisher >
</ book >
</ booklist >
运行结果:
namepricedescriptionpublisher
Ajax$5.95Foundations of Ajax.ABC company
Ajax Patterns$7.95Introduction of Ajax Patterns.ABC company
Ajax Web App$8.95Edition 2.ABC company
Core CSS$4.50A book for CSS.ABC company
JSF and Ajax$6.95Apress.ABC company
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值