xlst reference
TRANSCRIPT
-
7/29/2019 XLST Reference
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 expresspermission 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 m ay 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 w arranty. SAP and other SAP products and services mentioned herein as wel l as their respective logos are trademarks or
registered trademarks of SAP AG in Germany and other countri es. Please see www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information
and notices.
Note
This PDF document contains the selec ted topic and its subtopics (max. 150) in the selec ted structure.Subtopics from other structures are not included.
PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.
Page 1 of 14
http://help.sap.com/saphelp_nw73/helpdata/EN/a8/824c3c66177414e10000000a114084/frameset.htmhttp://help.sap.com/ -
7/29/2019 XLST Reference
2/14
SAP XSLT Processor ReferenceThe 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 s tatements 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
http://help.sap.com/saphelp_nw73/helpdata/en/7f/b7463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/f3/d5463c269f731ae10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/e8/e7463c6796e61ce10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/84/2e4d3ce624b800e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/3c/b7463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/09/b7463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/d6/b6463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/83/b6463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/50/b6463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/f8/af463c36a30319e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/c5/af463c36a30319e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/92/af463c36a30319e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/1c/b6463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/7f/b7463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/f3/d5463c269f731ae10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/e8/e7463c6796e61ce10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/84/2e4d3ce624b800e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/3c/b7463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/09/b7463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/d6/b6463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/e7/b5463c32a3fe13e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/fd/9d7348389211d596a200a0c94260a5/frameset.htm -
7/29/2019 XLST Reference
3/14
xsl:attribute
xsl:comment
xsl:copy
Constraints:
Theuse-attribute-sets attribute is not supported.
xsl:copy-of
xsl:elememt
Constraints:
Theuse-attribute-sets attribute is not supported.Notes on Conformity:
1. The validity of the element nameqName 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 usingxsl: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 thenamespace attribute is specified in the element statement, generally no namespace node is created in the result tree unless declaration of the specifiedURI is mandatory. If the name attribute contains a prefix, this prefix is not necessarily used - although it is preferred.b). However, if thenamespace attribute is not specified in the element statement, all the namespace declarations are copied to the created element in the result tree. Also, itis 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 theposition()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
-
7/29/2019 XLST Reference
4/14
xsl:choose
xsl:fallback
This statement is not supported.
xsl:for-each
xsl:if
xsl:otherwise
xsl:sort
Constraints:
Thelong 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, thestatement within the scope of another x bind can cause an error although it adheres to the rule given. However, a reference to x is stillallowed 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:
...
...
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 p arameters 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
-
7/29/2019 XLST Reference
5/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 "xs tring".
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:
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
-
7/29/2019 XLST Reference
6/14
xsl:attribute-set
This statement is not supported.
Solution:
Complete replacement ensured withxsl: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 usingxsl:element.
xsl:preserve-space
xsl:strip-space
Output
xsl:message
xsl:output
Constraint:
Thecdata-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 forsap: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
http://help.sap.com/saphelp_nw73/helpdata/en/76/084e3ce0f9fe3fe10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/dd/ae463c36a30319e10000000a114084/content.htm -
7/29/2019 XLST Reference
7/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 Functionssap: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:
...
...
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 p arameter 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 implici t 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:
...
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
http://help.sap.com/saphelp_nw73/helpdata/en/11/af463c36a30319e10000000a114084/content.htmhttp://help.sap.com/saphelp_nw73/helpdata/en/f8/af463c36a30319e10000000a114084/content.htm -
7/29/2019 XLST Reference
8/14
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
Forinstance methods:
...
Forclass methods:
...
Forconstructors:
...
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:
PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.
Page 8 of 14
http://help.sap.com/saphelp_nw73/helpdata/en/dd/ae463c36a30319e10000000a114084/content.htm -
7/29/2019 XLST Reference
9/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:
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
...
-
7/29/2019 XLST Reference
10/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
-
7/29/2019 XLST Reference
11/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
-
7/29/2019 XLST Reference
12/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 FunctionsThe 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
-
7/29/2019 XLST Reference
13/14
sap:if()
The functionsap:if( x,e1,e2 ) returns e1 ifx=true; otherwise, e2.
sap:let()
The functionsap:let( x,e1,e2 ) binds $x toe1 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 valuevalue_i. A placeholder is specified either as a string (reference through name) or as a number (reference through the position).
sap:otr-text()
The functionsap:otr-text(alias, ...) returns short texts from the OTR. An alias name is used to identify a short text. As forsap:otr-string() , the language andplaceholder 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 SequencesIn 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 Pr ogram 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 &&
-
7/29/2019 XLST Reference
14/14
PUBLIC Page 14 of 14