The XCO Library (ABAP Cloud) — part of SAP’s modern ABAP RESTful programming model — allows you to programmatically create and manipulate repository objects like CDS views, classes, and transformations (including XSLT).
CLASS zcl_create_xsl_demo DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS create_xsl.
ENDCLASS.
CLASS zcl_create_xsl_demo IMPLEMENTATION.
METHOD create_xsl.
” Get the package where the object will be created
DATA(lo_package) = xco_cp_abap_repository=>package->for( ‘Z_MY_PACKAGE’ ).
” Define the transformation name
DATA(lo_xsl_name) = xco_cp_abap_repository=>object_name->for( ‘Z_MY_XSLT’ ).
” Define the transformation source code
DATA(lv_xsl_source) = |<?xml version=”1.0″ encoding=”UTF-8″?>| &&
|\n<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>| &&
|\n <xsl:template match=”/”>| &&
|\n <output>| &&
|\n <xsl:value-of select=”/root/value”/>| &&
|\n </output>| &&
|\n </xsl:template>| &&
|\n</xsl:stylesheet>|.
” Create a new transformation object
DATA(lo_xsl_object) =
xco_cp_abap_repository=>object->transformation->create(
object_name = lo_xsl_name
package = lo_package
).
” Set the source code of the transformation
lo_xsl_object->source->set( lv_xsl_source ).
” Persist (activate) the transformation in the repository
lo_xsl_object->save( xco_cp_abap_repository=>activation_mode->active ).
WRITE: / ‘XSL Transformation Z_MY_XSLT created and activated successfully.’.
ENDMETHOD.
ENDCLASS.