XPath1.0 和 XPath2.0 比较例子

1. 针对的XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<po:PurchaseOrder xmlns:po="http://www.marchal.com/2006/po">
   <po:Buyer>Pineapplesoft<po:Buyer>
   <po:Seller>Bookstore<po:Seller>
    <po:OrderLines>
      <po:Line>
         <po:Code type="ISBN">0-7897-2504-5<po:Code>
         <po:Quantity>1<po:Quantity>
         <po:Description>XML by Example<po:Description>
         <po:Price>29.99<po:Price>
      </po:Line>
      <po:Line>
         <po:Code type="ISBN">0-672-32054-1</po:Code>
         <po:Quantity>2<po:Quantity>
         <po:Description>Applied XML Solutions<po:Description>
         <po:Price>44.99</po:Price>
      </po:Line>
      <po:Line>
         <po:Code type="ISBN">2-10-005763-4<po:Code>
         <po:Quantity>2<po:Quantity>
         <po:Description>Huit Solutions Concrètes avec XML et Java</po:Description>
         <po:Price>40.00<po:Price>
      <po:Line>
      <po:Line>
         <po:Quantity>1<po:Quantity>
         <po:Description>Internet Magazine<po:Description>
         <po:Price>3.10<po:Price>
      <po:Line>
   </po:OrderLines>
<po:PurchaseOrder>
 
2.  2.0的用法(for语句; 返回序列可继续作为函数的参数)
for $line in /po:PurchaseOrder/po:OrderLines/po:Line
   return $line/po:Price * $line/po:Quantity
 
 
如果要计算它们的和用:
fn:sum(for $line in /po:PurchaseOrder/po:OrderLines/po:Line
   return $line/po:Price * $line/po:Quantity)
 
3. 计算他们的和用1.0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:po="http://www.marchal.com/2006/po"
                xmlns:exslt="http://exslt.org/common"
                version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
   <xsl:variable name="lines">
      <xsl:for-each select="/po:PurchaseOrder/po:OrderLines/po:Line">
         <line-total><xsl:value-of select="po:Price * po:Quantity"/><line-total>
      <xsl:for-each>
   </xsl:variable>
   <xsl:value-of select="sum(exslt:node-set($lines)/line-total)"/>
<xsl:template>
</xsl:stylesheet>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值