Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: xsl totals composed from variables [Thread Next] Re: xsl totals composed from variablesTo: NULL Date: 11/5/2006 11:05:00 PM the_jos wrote: > I then found out that xml/xsl does not > handle variables the way a program language does. But that's not > entirely strange, given the nature of xsl. Actually, XSLT handles variables very much the same way other nonprocedural programming langauges do -- single-assignment, lexically scoped. > For my question, I just wanted to determine the value of legs (25), > chair_top (25) and table_top (50) given the price of wood and work. This is as much a data-representation problem as a stylesheet problem. If your data hierarchy matches the structural hierarchy, gathering the structured information becomes much easier -- for example, if the data is something like <set> <table quantity="1"> <top quantity="1" hours="2" wood="2" price="100"/> <leg quantity="4" hours="1" wood="1" price="25"/> </table> <chair quantity="4"> <top quantity="1" hours="1" wood="1" price="50"/> <leg quantity="4" hours="1" wood="1" price="25"/> </chair> </set> then this becomes a fairly straightforward recursive multiply-and-accumulate problem. (Value at any node is sum of values of its children times their quantity, plus its own value if any.) That isn't necessarily the best solution; there are several other possible ways to structure this. Note that this provides all the information in a single document. If you really wanted to separate the values from the Picking the minimum of two results is simple once you've got the values, of course. This isn't a typical use of XSLT, of course. It's more typical of what one will do using XQuery... but XQuery and XSLT 2.0 are essentially the same language with different syntax. -- () ASCII Ribbon Campaign | Joe Kesselman /\ Stamp out HTML e-mail! | System architexture and kinetic poetry | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
