0% found this document useful (0 votes)
156 views

XLST Reference

XLST SAP ABAP Reference

Uploaded by

thiarllisb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views

XLST Reference

XLST SAP ABAP Reference

Uploaded by

thiarllisb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

PRINT FROM SAP HELP PORTAL

Document: SAP XSLT Processor Reference URL: http://help.sap.com/saphelp_nw73/helpdata/EN/a8/824c3c66177414e10000000a114084/frameset.htm Date created: July 26, 2013

2013 SAP AG or an SAP affiliate company. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. National product specifications may vary. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Please see www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.

Note This PDF document contains the selected topic and its subtopics (max. 150) in the selected structure. Subtopics from other structures are not included.

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 1 of 14

SAP XSLT Processor Reference


The SAP XSLT processor is part of the kernel. To ensure efficient support for the XSL transformation in the development of ABAP-based applications, an appropriate infrastructure will be made available. For this purpose, the XSL transformation is represented within the ABAP Workbench by a special Repository object, the XSLT program. You can create objects of this type in SE80 and process them in the Transformation Editor. CALL TRANSFORMATION is a new language element in ABAP that you can use to call up the transformation. The type of transformation (XML to XML, XML to ABAP, ABAP to XML, or ABAP to ABAP) is already determined by the two additions SOURCE and RESULT in CALL TRANSFORMATION. SAPs own implementation of the processor conforms, for the most part, with the specifications defined for the XSLT 1.0 version as given under http://www.w3.org/TR/1999/REC-xslt-19991116. The following documentation lists the few exceptions and the SAP-specific enhancements. We use the following conventions to indicate the status for each corresponding XSL element: Means that the element conforms completely to the specifications given for XSLT 1.0. Means that the element is not supported at all. Means that the element does not completely conform to the specifications given for XSLT 1.0. This means there are differences compared to the specifications for example, certain constrains or even enhancements. Means that the element is an SAP-specific enhancement in the form of additional statements or additional functions.

Reference
Statements Creating the Result Tree Flow Control Defining and Calling Template Rules Stylesheets and Structuring Top-Level Help Statements Output Additional SAP Statements Functions XPath Functions XSLT Functions Additional SAP Statements Preprocessor Sequences General Constraints

Statements
The URI for the statements is: http://www.w3.org/TR/xslt. Creating the Result Tree Flow Control Defining and Calling Template Rules Stylesheets and Structuring Top-Level Help Statements Output Additional SAP Statements

Creating the Result Tree

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 2 of 14

xsl:attribute xsl:comment xsl:copy


Constraints: The use-attribute-sets attribute is not supported.

xsl:copy-of xsl:elememt
Constraints: The use-attribute-sets attribute is not supported. Notes on Conformity: 1. The validity of the element name qName is not checked. 2. The specifications do not expressly require that namespace declarations that apply to the corresponding element statement are copied to the result tree. However, it is quite useful to have this option. The reason for this is that there is no alternative to declaring elements that are created using xsl:element. In our implementation method, therefore, the element statement can be used in two different ways: in one case, the namespace declarations are copied to the result tree; in the other case, they are not. a). If the namespace attribute is specified in the element statement, generally no namespace node is created in the result tree unless declaration of the specified URI is mandatory. If the name attribute contains a prefix, this prefix is not necessarily used - although it is preferred. b). However, if the namespace attribute is not specified in the element statement, all the namespace declarations are copied to the created element in the result tree. Also, it is ensured that the prefix specified in the name attribute is used for the result node.

xsl:number
This element is not supported. Instead, you can use the position()function or a parameter for a counter.

xsl:processing-instruction xsl:text xsl:value-of

Flow Control

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 3 of 14

xsl:choose xsl:fallback
This statement is not supported.

xsl:for-each xsl:if xsl:otherwise xsl:sort


Constraints: The long atrribute is ignored.

xsl:variable
Notes on Conformity: We have not adhered strictly to the rule for the scope of variables in our implementation, as compared with the actual specifications. For example, the statement <xsl:variable name ="x"> within the scope of another x bind can cause an error although it adheres to the rule given. However, a reference to x is still allowed in this case if it comes after the x bind and is outside its scope. Example: It is possible to access x, therefore, in the last of the following statements using $x: <A> ... <xsl:variable name ="x" select= "..."/> ... </A> <xsl:value-of select="$x"/> This inadequacy in the semantics of the compiler check will be removed in future versions. However, in your own XSLT programs, you should not use this option at all.

xsl:when

Defining and Calling Template Rules


xsl:apply-templates

xsl:call-template

xsl:param Notes on Conformity: Top-level parameters can be assigned the required XSLT types. xsl:template Appropriate match patterns will be accepted in addition to the ones in the specifications. Example: (A | B) / C xsl:with-param

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 4 of 14

Stylesheets and Structuring


xsl:apply-imports Notes on Conformity: Parameters can be passed to the called template in the same way as for xsl:apply-templates using xsl:with-param. xsl:import Notes on Conformity: The specifications do not contain an exact statement on how imports to... is to be understood. But this is of particular interest for the use of includes. Let us assume that an XSLT program A includes programs B and C, and C in turn imports program D. It is now clear that D will be imported to C and A. But what is the case for B? - In our implementation, we assume that D is also imported to B (in the context of A). This is based on the assumption that there is a distinction between the two importing units U1 = {A, B, C} and U2 = {D} and there is an import relationship from U1 to U2. The consequence of this is that template rules from D are candidates for the statement xsl:apply-imports within B (in the context of A). Our definition of imports to... is therefore to be understood as follows: a). Import units are defined as nodes in the import tree. b). The relationship imports to... is defined between the import units through the (transitive) relationship in the import tree. c). Program Y is imported into program X if the import unit of Y has been imported into the import unit of X. xsl:include Notes on Conformity: The inclusion uses the name from the repository instead of a URL. This name is specified in the sap:name attribute. The href attribute no longer applies in this case. xsl:stylesheet Constraints: The extension-element-prefixes attribute is not supported. Notes on Conformity: XSLT types of stylesheet parameters can be specified as top-level parameters with the statement xsl:param through the sap:type attribute. The following type descriptions can be used as values for sap:type: "string", "number", "boolean", "node-set", "external", and "xstring". The triggers a type conversion on the ABAP side. Example In the standard version, a date in ABAP is passed as a string ("2001-05-16"). With the parameter declaration: <xsl:param name="p" sap:type="number"> the date is first converted on the ABAP side into a number (number of days from 0001-01-01), and this number is then passed to the XSLT program. xsl:transform See also: Note for xsl:stylesheet.

Top-Level Help Statements

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 5 of 14

xsl:attribute-set
This statement is not supported. Solution: Complete replacement ensured with xsl:attribute or also through literal result attributes.

xsl:decimal-format
This statement is not supported because xsl:number is not supported either.

xsl:key xsl:namespace-alias
This statement is not supported. Solution: As a rule, this statement is only important for stylesheets that generate stylesheets themselves. Result elements in the XSLT namespace can be created using xsl:element.

xsl:preserve-space xsl:strip-space

Output
xsl:message xsl:output
Constraint: The cdata-section-elements attribute is not supported.

Additional SAP Statements


The URL for these SAP enhancements is: http://www.sap.com/sapxsl. ABAP Calls As a rule, a transformation can and should be described using XSLT elements. However, it can often be very useful to access additional data from within an XSLT program for example, data in the database or to execute calculations in procedures. For this purpose, ABAP calls have been integrated as enhancements into the SAP XSLT processor. In this way, you can define constructor calls and class method calls in XSLT programs in addition to method calls for ABAP objects that are included as program parameters.

Remember that XSLT is a declarative language. The sequence in program execution is not fixed. ABAP calls should therefore be limited to read access. However, possible state manipulations are an exception here. But these are visible during transformation execution. For further information, see the syntax documentation for sap:call-external and sap:external-function. Defining Your Own XPath Functions Named templates are available and they provide a mechanism for you to be able to define even recursive functions at the level of the tree transformations. However, this option is missing entirely at the XPath level.

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 6 of 14

Here the SAP XSLT processor provides an enhancement that supports you in defining your own XPath functions. Functions of this type always have their own namespace (not XSLT or SAP XSLT namespace) and are generally used in connection with the additional SAP Functions sap:if( ) and sap:let( ). For more information on this topic, refer to the syntax documentation for sap:function.

sap:call-external
Use
Using the statement sap:call-external, you can perform ABAP calls with any number of return values from within an XSLT program. These calls can take place both at the instance level of ABAP classes and at the class level itself. In the first case, therefore, instance methods are used; in the second, on the other hand, class methods are used. When calling interface methods, these must be indicated with the name of the interface followed by the interface component selector (intf~ ).

Syntax
Calling instance methods is performed according to the following syntax: <sap:call-external name=" prefix:localname" method=" instanceMethod"> <sap:callvalue param=" inParam1" select=" expression"/> <sap:callvalue param=" inParam2" select=" expression"/> ... <sap:callvariable param=" exParam1" name=" varName1" type=" xslType"/> <sap:callvariable param=" exParam2" name=" varName2" type=" xslType"/> ... </sap:call-external> Description The statement sap:call-external can be at any position in the XSL source code where xsl:call-template is also allowed otherwise. Calling an instance method requires the specification of an object name that identifies an ABAP object and the name of the method to be called. Both sub-statements sap:callvalue and sap:callvariable are required for passing parameter values. Using sap:callvalue, parameter values are passed to the called method as import parameters. The attribute param specifies one parameter name each from the method definition in ABAP; the value assignment takes place with the attribute select. Here the XSLT types string, number, boolean, and node-setcan be passed to the ABAP parameters. Example: Conversion of the types number and node-set, for example, into the corresponding ABAP values is performed according to the following scheme: A value of the type number can be compiled in ABAP both into an integer as well as into a float type. A node set is always converted into an iXML node collection. Note that there can be no implicit conversion of node sets into strings. For example, to pass the value of an attribute "attr" to a string parameter in ABAP, the XPath expression string(@attr)must be used. The values returned from the method call are bound to XSLT variables using the sub-statement sap:callvariable. Here the attribute param specifies the ABAP parameter name from the method definition. The attribute name, on the other hand, identifies the corresponding XSLT variable. In addition, the attribute type can be used to assign the resulting values to a particular XSLT type. Otherwise, the standard conversion is used. Example: Data of type C(1) is converted by default into an XSLT string. However, if boolean is specified explicitly in the attribute type, the conversion is into XSLT boolean, accordingly.

Generally speaking, ABAP objects can also be specified as parameters. Note that ABAP parameters of the type changing can be passed both using sap:callvalue as well as sap:callvariable When the class methods are called, the attribute name is replaced by class. The value for class must be specified accordingly with the name of the ABAP class, and the value for method with the name of the required class method. Therefore, the syntax is as follows: <sap:call-external class=" className" method=" clasMethod"> ... </sap:call-external>

Example
The following example demonstrates an access to the database of the SAP system with which additional data is output for a selected flight connection. The call takes place using the class method GET_DETAIL for the class CL_FLIGHT_INFO. The information received is bound to the corresponding XSLT variables (duration, distance, unit, ...) using sap:callvariable.

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 7 of 14

<sap:call-external class="CL_FLIGHT_INFO" method="GET_DETAIL"> <sap:callvalue param="AIRLID" select="string($carr/@code)"/> <sap:callvalue param="CONNID" select="string(@code)"/> <sap:callvalue param="FLDATE" select="string(departure/date)"/> <sap:callvariable param="FLIME" name="duration"/> <sap:callvariable param="DIST" name="distance" type="number"/> <sap:callvariable param="UNIT" name="unit"/> <sap:callvariable param="PLTYPE" name="planetype"/> <sap:callvariable param="SEATSM" name="seatsmax"/> </sap:call-external>

sap:external-function
Use
Using the statement sap:external-function you can declare a function for ABAP calls from within XPath. In contrast to sap:call-external, only one single return value can be specified for the method call. For this purpose, the method to be called must be declared in the top level of the XSLT program as an external function. Functions declared in this way can be used for method calls in XPath expressions.

Functions of this type always use their own namespace (not XSLT or SAP-XSLT namespace). When calling interface methods, these must be indicated with the name of the interface followed by the interface component selector (intf~ ).

Declaration Syntax
For instance methods : <sap:external-function name=" prefix:fName" method=" instanceMethod" kind="instance"> <sap:argument param=" PARAM_1"/> <sap:argument param=" PARAM_2"/> ... <sap:result param=" RESULT" type=" xslType"/> </sap:external-function> For class methods : <sap:external-function name=" prefix:fName" class="className" method=" classMethod" kind="class"> <sap:argument param=" PARAM_1"/> <sap:argument param=" PARAM_2"/> ... <sap:result param=" RESULT" type=" xslType"/> </sap:external-function> For constructors : <sap:external-function name=" prefix:new" class=" className" kind="constructor"> <sap:argument param=" PARAM_1"/> <sap:argument param=" PARAM_2"/> ... </sap:external-function> Description With the exception of the constructor declaration, the attribute method outputs the name of the ABAP method to be called. The attribute kinddefines, in addition, whether you have an instance or class method, or a constructor. For class methods and constructors, the name of the ABAP class is output using the attribute class. The list of function arguments is declared using the sub-statement sap:argument (with consideration of the sequence). The names of the corresponding ABAP parameters are specified using the attribute param. Calls of instance and class method can define a return value using the sub-statement sap:result. The name of the return parameter is specified through the attribute param. Optionally, you can assign a particular XSLT type (string, number, boolean, node-set, or external) to the result using the attribute type.

Syntax for Calls in XPath Expressions


Declared functions can be used in XPath expressions for ABAP calls. With instance methods, the first function argument must be identified using an ABAP object. Example: <xsl:value-of select="prefix:f1($x,99,'abc')"/>

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 8 of 14

In the example given, the function with the name prefix:f1 defines an ABAP call using an instance method that passes the two values 99 and 'abc' as input parameters. The first function argument $x identifies the required ABAP object. If you are using a suitable declared constructor function, this call can also be written alternatively as follows: <xsl:value-of select="prefix:f1(prefix:new('xyz'),99,'abc')"/>

sap:function
Use
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).

Syntax
<sap:function name=" prefix:fName"> <sap:argument name = " arg1"/> <sap:argument name = " arg2"/> ... <sap:result define = " <!-- function definition --> "/> </sap:function> Description 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.

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 &lt;= 0, 0, sapxsl:if($n=1, 1, $n*p:fact($n-1)))"/> </sap:function>

Functions
XPath Functions XSLT Functions Additional SAP Statements

XPath Functions
PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved. Page 9 of 14

See also the specifications for XPath functions in: http://www.w3.org/TR/xpath#corelib

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 10 of 14

last() position() count() id() local-name() namespace-uri() name() string() concat() starts-with() contains() substring-before() substring-after() substring() string-length() normalize-space() translate() boolean() not() true() false() lang
This function is not supported.

number() sum()

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 11 of 14

floor() ceiling() round()

XSLT Functions
See also the specifications for XSLT functions in: http://www.w3.org/TR/xslt#add-func

document()
Constraints: 1. This function is supported only for an argument that, additionally, must not be a node set. 2. Relative URLs are not expanded. However, it is possible to reference the root of the stylesheet document using document("").

key() format-number()
This statement is not supported.

current() unparsed-entity-uri()
This statement is not supported.

generate-id() system-property() element-available function-available

Additional SAP Functions


The following list shows the functions that have been implemented in the SAP-XSLT enhancement http://www.sap.com/sapxsl.

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 12 of 14

sap:if() The function sap:if( x,e1,e2 ) returns e1 if x=true; otherwise, e2. sap:let() The function sap:let( x,e1,e2 ) binds $x to e1 in e2. Example : sap:let( x,4,$x+$x ) returns the value 8. sap:let( ) displays the syntax of an extension function, but it is used as a construct for a variable bind. sap:node-set() sap:node-set(e) converts a fragment of the result tree into a node set. The resulting node set contains its own node, which is the fragment root. sap:intersection() sap:intersection( node-set1,node-set2 ) gives the intersection of the two node sets node-set1 and node-set2 zurck. sap:otr-string() This function returns OTR (Online Text Repository) strings. An alias name is used to identify a string. A distinction can be made between the following variants: sap:otr-string(alias) returns OTR strings for an alias in the current language. sap:otr-string(alias, language) returns OTR strings for an alias in the specified language. sap:otr-string(alias, id_1, value_1, ...id_n, value_n [,language]) returns OTR strings for an alias in the specified/current language; however, the corresponding placeholder id_i is replaced by the appropriate value value_i. A placeholder is specified either as a string (reference through name) or as a number (reference through the position). sap:otr-text() The function sap:otr-text(alias, ...) returns short texts from the OTR. An alias name is used to identify a short text. As for sap:otr-string(), the language and placeholder can be specified as further function arguments. sap:otr-line() sap:otr-line(node-set) returns the line number of the first node of the node set in the source document. sap:otr-line() returns the line number of the node from the current context. sap:otr-column() sap:otr-column(node-set) returns the column number of the first node of the node set in the source document. sap:otr-column() returns the column number of the node from the current context.

Preprocessor Sequences
In the SAP Repository, the line length for XSLT programs is limited to 255 characters. However, in XML and particularly in XSLT, there are certain cases where long lines without a line break are required. Often, too, filling blanks are required before a line break. This is supported through a simple form of "preprocessing". Continuing Program Lines The sequence &> at the end of the editor line indicates that the current program line will be continued in the following editor line. "Whitespaces" (blanks, tabulators, and so on) before the &>sequence are kept. However, if &> are inserted at the end of an editor line as actual program characters, the escape sequence &&> must be used instead. Keeping Filling Blanks The &< sequence at the end of an editor line has the effect that "whitespaces" before &< are kept and then a line break follows. However, if &< are inserted at the end of an editor line as the actual program characters, the escape sequence &&< must be used instead.

General Constraints
Unicode Internal Unicode processing (based on iXML DOM) supports UCS-2, but not UTF. The integrated XPath parser is currently not Unicode-enabled. Therefore, non-ASCII Unicode characters are not supported in XPath attribute values. Forwards Compatibility The forwards-compatible mode is not supported. The attribute for the stylesheet version must therefore be "1.0".

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 13 of 14

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 14 of 14

You might also like