[Top] [All Lists]

Re: [xsl] How to dynamically evaluate an equation in the input XML document?

2021-07-15 02:11:24
On Wed, 2021-07-14 at 18:49 +0000, Roger L Costello 
Hi Folks,

I have XML documents like this:

    <equation>(Fahrenheit - 32) * (5/9)</equation>

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 Quin, 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:  http://www.fromoldbooks.org
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>