The abs() function

Smartsite 7.4 - ...

The abs() XPath 2.0 function returns the absolute value of arg.

XML CopyCode image Copy Code
numeric fn:abs(arg)

Parameters:

  • arg: a node reference or literal.

Example

XML CopyCode image Copy Code
<html xmlns="http://www.w3.org/1999/xhtml" 
 xmlns:xf="http://www.w3.org/2002/xforms" 
 xmlns:fn="http://www.w3.org/2005/xpath-functions"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <head>
  <title>Example</title>
  <xf:model>
   <xf:instance>
    <data xmlns="">
     <pos>10.5</pos>
     <neg>-10.5</neg>
    </data>
   </xf:instance>
  </xf:model>
 </head>
 <body>
  <xf:group>
   <xf:output value="fn:abs(pos)" />
   <xf:output value="fn:abs(neg)" />
   <xf:output value="fn:abs(10.5)" />
   <xf:output value="fn:abs(-10.5)" />
  </xf:group>
 </body>
</html>

The result will be:

10.5 for each output.

Namespace

This function is available within the XPath 2.0 namespace (http://www.w3.org/2005/xpath-functions).