The statement sap:function allows you to define new XPath functions in XSLT programs.

Note that these user-defined additional functions always use their own namespace (not XSLT or SAP-XSLT namespace).


<sap:function name="prefix:fName">

   <sap:argument    name = "arg1"/>

   <sap:argument    name = "arg2"/>


   <sap:result      define = "

                            <!-- function definition -->




All function arguments are declared using the sub-statement sap:argument. These are specified solely by their names.

The result of the function is defined as an XPath expression for the attribute define within the sub-statement sap:result. The function body can contain calls of functions that are already defined.

Several functions can also be called with the same name, provided they differ in their arguments.


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 &lt;= 0,