Subject: Re: [xsl] How to dynamically evaluate an equation in the input XML document? From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 15 Jul 2021 07:11:17 -0000 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to dynamically evalua, Mukul Gandhi mukulg@ | Thread | Re: [xsl] How to dynamically evalua, Dimitre Novatchev dn |
Re: [xsl] How to dynamically evalua, Mukul Gandhi mukulg@ | Date | Re: [xsl] How to dynamically evalua, Dimitre Novatchev dn |
Month |