[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

Subject: Re: 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
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.