Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

evaluate function 1

Status
Not open for further replies.

Naug

Technical User
Sep 24, 2004
85
RU
Is there an evaluate function that would allow to xsl transforming e.g. 8*4 into 32?
 
What if I need an atribute and not text tag? I better give example I suppose. I have a node

Code:
<float>47*4</float>

what I want in output is
Code:
<float value="188">188</float>
 
Code:
<float value="{7 * 4}"><xsl:value-of select="7 * 4"/></float>
 
value="{7 * 4}"

well how do I do that? I am trying value="{normalize-space(text())}"

but as result I simply get value="47*4" rather then the evaluation of the expression
 
Ah, OK. I see what you mean now.

As far as I know, there's no XPath function that will evaluate an expression, but I'm looking into it.

Here's a way you could do it:
Code:
<float value="{substring-before(float, '*') * substring-after(float, '*')}"><xsl:value-of select="substring-before(float, '*') * substring-after(float, '*')"/></float>
 
Works. Xept I swaped "form" for "text()" in the expressions but thats prolly cause tag-name in result isnt float (I left it as float to simplify the example)
 
Any idea how do I do if Im not sure what action "*/-+" will be required if any at all? Only thing I can figure is to myself make some sort of "math" node which will have relevant attribute
 
Could there be a combination of these, eg:

<float>47*8+3</float>

or is there always only 1 operator?
 
Could be anything and brackets and all... Or no operator at all which also needs separate case. Do you think parameters can be used? I never used em.
 
You could create a template that will parse the string and calculate the expression using different cases for *, +, /, - and ()'s etc but it would be a lot easier to do this in ASP or something. Are you creating the XML or processing from an outside source?
 
Ya I actually rewrote this to do the calc in database
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top