BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


XSLT
XML to HTML text editor
Dynamically Selecting Which Element To Sort On Using Parameters
Avoid NaN in XPath sum() function
JScript Super Class To Handle XML Transformations
Test if a bit is on
Web Methodology (Layout Management)
Grouping an XML Node by First Letter
Dependent ComboBox in HTML build with XSLT
Re: How to use XSL function sum() to sum 2 XML fields
Re: How to use XSL function sum() to sum 2 XML fields
How to use XSL function sum() to sum 2 XML fields
Helpful XSLT ""break"" template
Support automatic transformation using XSLT in IE in side by side mode
Displaying XML data in Pages
Repeated search and replace in XSLT
DVC Algorithms in XSLT
Another way of avoiding XSLT processor crash
Re: DVC Algorithms in XSLT
trig functions in xslt
XSLT string Replace function


 
 

<< XQuery.NET and XML >>


By Dimitre Novatchev
First Posted 04/05/2001
Times viewed 180

ABS function implemented as a single XPath expression


Summary This snippet shows how to implement the abs() function as a single XPath expression

We need an XPath implementation of the classical abs() math function, defined as: abs(x) = x iff x >= 0 abs(x) = -x otherwise The expression is: concat( substring('-', 2 - ($pNum <0)), '1' ) * $pNum For a more general approach to conditionally generating strings within a single XPath expression, see another snippet: http://www.vbxml.com/snippetcentral/main.asp?view=viewsnippet&id=v20010328225824 Other XPath expressions implementing the abs() function have been also suggested by Bejamin Guralnik, John Ardiss, and Samuel Chen: $pNum * (translate(number(boolean(0 >= $pNum )),'10','13') - 2) ((($pNum > 0) * $pNum) + (($pNum < 0) * -$pNum)) substring('-1', 2 - ($pNum < 0)) * $pNum

Additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< XQuery.NET and XML >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML