[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to dynamically evaluate an equation in the inp
On Wed, 2021-07-14 at 18:49 +0000, Roger L Costello costello@xxxxxxxxx wrote: > Hi Folks, > > I have XML documents like this: > > <Convert-to-Celsius> > B B B <equation>(Fahrenheit - 32) * (5/9)</equation> > B B B <variable> > B B B B B B B <name>Fahrenheit</name> > B B B B B B B <value>32</value> > B B B </variable> > </Convert-to-Celsius> > > The document contains an equation which might contain variables. If it > does contain variables, then I need to fetch their values and replace > the variables in the equation with their values and then compute the > value of the equation. > > Have you done this kind of dynamic equation solving using XSLT? If so, > how did you do it? I would probably *not* use fn:evaluate or saxon:evaluate unless it's an XPath expression (doesn't look like it). You could use https://www.bottlecaps.de/rex/ to generate a parser for a simple grammar; this would be much safer than using eval(). The hacky way is to use replace() to change / to div, and to interpolate variable values, and then use eval(), but make sure there are no function calls first, as saxon:eval() can execute arbitrary Java, which can include running external programs, modifying files, connecting over the network to other systems... Liam -- Liam Quin,B https://www.delightfulcomputing.com/ Available for XML/Document/Information Architecture/XSLT/ XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. Barefoot Web-slave, antique illustrations: B http://www.fromoldbooks.org
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|