xslt 1和求和函数 [英] xslt 1 and sum function

查看:114
本文介绍了xslt 1和求和函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用xml和PHP创建了发票管理系统,但是最新的PHP版本不支持XSLT 2.0-因此,我必须寻找sum()替代方案.如何将有效的xslt 2函数"sum(unitprice *数量)"转换为xslt 1.0?

I create an invoice management system using xml and PHP but the latest PHP version does not support XSLT 2.0 - therefore I have to look for an sum() alternative. How can I transform the valid xslt 2 function "sum(unitprice * quantity)" to xslt 1.0 ?

XML内容基于约翰的示例

我尝试使用节点集进行尝试,但是不支持"xmlXPathCompOpEval:在其中找不到函数节点集"

I tried it with a node-set, but it is not supported "xmlXPathCompOpEval: function node-set not found in"

推荐答案

实际上,sum(price*quantity)不是有效的XSLT 2.0语法.我猜你的意思是像`sum($ x in * return $ x/price * $ x/quantity)之类的东西.

Actually, sum(price*quantity) isn't valid XSLT 2.0 syntax. I guess you mean something like `sum(for $x in * return $x/price*$x/quantity).

可以通过以下方式对XSLT 1.0中的计算值求和:

Summing over a computed value in XSLT 1.0 can be done in the following ways:

  • 两次通过解决方案,创建一个节点集,其中的节点保存计算值,然后对节点集求和

  • two pass solution, create a node-set in which the nodes hold the computed values, then sum over the node-set

递归解决方案:编写一个递归模板,该递归模板将总数作为参数传递,为当前节点添加sum * quantity,然后递归以处理其余节点

recursive solution: write a recursive template that passes the total so far as a parameter, adds sum*quantity for the current node, then recurses to process the remaining nodes

高阶解决方案:使用Dimitre Novatchev的FXSL库

higher-order solution: use Dimitre Novatchev's FXSL library

扩展解决方案:使用诸如saxon:sum()

extension solution: use extension functions like saxon:sum()

这篇关于xslt 1和求和函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆