XPath1.0 和 XPath2.0 比较例子
2008-11-02 22:20
417 查看
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>
<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>
相关文章推荐
- hadoop1.0 和hadoop2.0 任务处理架构比较
- 从读取图像程序比较opencv1.0与opencv2.0以上版本
- 从读取视频程序比较opencv1.0与2.0以上版本
- HTTP/1.0和HTTP/1.1,HTTP/2.0的比较
- 【第一章】C#的进化史——C#1.0,2.0,3.0区别比较(二)——C#2.0,3.0 简化排序的特性
- struts1.0于struts2.0的比较
- 【第一章】C#的进化史——C#1.0,2.0,3.0区别比较(三)——查询集合
- XPath Kick Start: Navigating XML with XPath 1.0 and 2.0 (Kick Start)
- hadoop1.0 和hadoop2.0 任务处理架构比较
- XPath 2.0, XQuery 1.0 和 XSLT 2.0 函数参考
- RxJava 版本1.0 和 版本2.0的比较
- JDBC 1.0 - 2.0 - 3.0 - 4.0简单比较
- AngularJS2.0 一个表单例子——总体说来还是简化了1.x 使用起来比较自然
- 【第一章】C#的进化史——C#1.0,2.0,3.0区别比较(一)
- PowerShell1.0 与2.0中的异常处理比较
- 复利计算1.0,2.0,3.0
- 复利计算1.0,2.0,3.0总结
- struts 2.0 两个简单例子
- play! framework 1.2.4 vs 2.0 比较
- Apache 2.0中prefork.c模块和worker.c模块的比较