Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

php - xslt 1 and sum function

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 ?

The XML stuff is based on John's Examples

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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

  • 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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...