XSLT Extension Functions

Use

The extension mechanism of the SAP xslt processor works as follows: for each Java class used, there is a namespace extension that contains the fully qualified name of the class in the namespace java:.

Example: xmlns:Guid="java:com.sap.basis.ukm.Guid"

Methods can be called wherever xpath expressions are allowed. The namespace defined for the class, followed by the method name, is used. The predefined method new(), which is used to create new instances, is a special case here. Such an instance is normally stored in a variable for later use (reference variable).

When instance methods are called, this reference variable is passed as the first argument. This is a special notation for xslt extension functions; this argument is not contained in the signature of the methods.

Static methods are always called without a reference variable.

Return Codes

The extension functions used here return values of type String (java.lang.String) as well as xml fragments of type Node (org.w3c.dom.Node). Before you can access values of type Node in the xslt program, the xpath context must be restored. This is an xslt specialty and normally occurs in an empty <xsl:for-each select="$variable"/>  loop.

For more information about the xslt extension mechanism, see the literature as well as the online help for the xslt processor: http://help.sap.com

Example

 A complete coding example with the namespace extensions for most of the classes offered in unified key mapping is given below. Creation of an instance of class AddKeyMapping is shown.

 

<?xml version="1.0" encoding="UTF-8" ?> <xsl:transform version="1.1"         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"         xmlns:Identifier="java:com.sap.basis.ukm.Identifier"         xmlns:GetKeyMapping="java:com.sap.basis.ukm.GetKeyMapping"         xmlns:AddKeyMapping="java:com.sap.basis.ukm.AddKeyMapping"         xmlns:Guid="java:com.sap.basis.ukm.Guid"> <xsl:param name="mappingTrace"/> <!-- Create an instance of AddKeyMapping  --> <xsl:variable name="add" select="AddKeyMapping:new($MappingTrace)"/> </xsl:transform>

 

The reference variable add can be used in the following calls of AddKeyMapping methods.