New XPath functions can be defined in XSLT programs using the instruction sap:function.
<sap:function name="prefix:fName"> <sap:argument name = "arg1"/>
<sap:argument name = "arg2"/> ...
<sap:result define = "
<!-- function definition -->
"/> </sap:function>
All function arguments are declared using the sub-instruction sap:argument. They are specified only by their names.
The result of the function is defined as an XPath expression for the define
attribute within the sub-instruction sap:result. The function body can contain calls to previously defined functions.
Hint
Multiple functions can be called with the same name, if they have different arguments.
Example
You can define a function for calculating the factorial as follows.
<sap:function name ="p:fact"> <sap:argument name ="n"/>
<sap:result define ="sapxsl:if($n <= 0,
0,
sapxsl:if($n=1,
1,
$n*p:fact($n-1)))"/> </sap:function>