2006 Nov 08 12:52 PM
hello,
is it possible in abap to create on runtime a xml stylesheet?
kind regards
sebastian
2006 Nov 08 1:00 PM
Hi Sebastian,
Check out the code below. May be of some help to you.
Here a successful implementation of Function module "SAP_CONVERT_TO_XML_FORMAT" for users of SAP 46c. It converts an internal table to an xml-table and downloads it.
This code needs 3 variables: FILENAME, XML-document-Name DOC_NAME(freetext) and the internal table (TAB) which you want to convert to XML.
TYPES: TRUXS.
TYPES : BEGIN OF TRUXS_XML_LINE,
DATA(256) TYPE X,
END OF TRUXS_XML_LINE.
TYPES: TYPE_XMLTAB TYPE TABLE OF TRUXS_XML_LINE.
DATA: XMLTAB TYPE TYPE_XMLTAB, BIN_SIZE TYPE I.
data: xml_tab type table of truxs_xml_line,
Xml_tab2 type
CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = ''
I_LINE_HEADER = ''
I_FILENAME = FILENAME
I_APPL_KEEP = ''
I_XML_DOC_NAME = DOC_NAME
IMPORTING
PE_BIN_FILESIZE = BIN_SIZE
TABLES
I_TAB_SAP_DATA = TAB
CHANGING
I_TAB_CONVERTED_DATA = XMLTAB
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = BIN_SIZE
CODEPAGE = ' '
FILENAME = FILENAME
FILETYPE = 'BIN'
MODE = ' '
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
COL_SELECT = ' '
COL_SELECTMASK = ' '
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = XMLTAB
FIELDNAMES =
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
<b>SECOND PROGRAM:</b>
REPORT abc.
*----
DATA
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
DATA : BEGIN OF itab OCCURS 0,
a(100) TYPE c,
END OF itab.
DATA: xml_out TYPE string .
DATA : BEGIN OF upl OCCURS 0,
f(255) TYPE c,
END OF upl.
DATA: xmlupl TYPE string .
FIRST PHASE
*----
Fetch Data
SELECT * FROM t001 INTO TABLE t001.
*----
XML
CALL TRANSFORMATION ('ID')
SOURCE tab = t001[]
RESULT XML xml_out.
CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
EXPORTING
TEXT = xml_out
IMPORTING
LENGTH =
TABLES
FTEXT_TAB = itab.
.
*----
Download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filetype = 'BIN'
filename = 'd:\xx.xml'
TABLES
data_tab = itab.
SECOND PHASE
BREAK-POINT.
REFRESH t001.
CLEAR t001.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\XX.XML'
filetype = 'BIN'
TABLES
data_tab = upl.
LOOP AT upl.
CONCATENATE xmlupl upl-f INTO xmlupl.
ENDLOOP.
*----
XML
CALL TRANSFORMATION ('ID')
SOURCE XML xmlupl
RESULT tab = t001[]
.
Reward points if this helps.
Manish
2006 Nov 08 1:04 PM
Yes, have a look at the iXML library for ABAP...
http://help.sap.com/saphelp_nw04/helpdata/en/47/b5413acdb62f70e10000000a114084/frameset.htm<a href="http://help.sap.com/saphelp_nw04/helpdata/en/47/b5413acdb62f70e10000000a114084/frameset.htm">http://help.sap.com/saphelp_nw04/helpdata/en/47/b5413acdb62f70e10000000a114084/frameset.htm</a>
2006 Nov 08 1:25 PM
Thank you for your quick answers, but I think I described my problem wrong.
I know how to create XML in ABAP with iXML and how to transform XML Source by XSLT programs (call transformation ... )
What I want to do is, to create on runtime a "xml stylesheet" as string respectively a XSLT program which can be called with "call transformation".
With class cl_xslt_processor and the method set_expression and run is it only possible to retrieve a node by a location paths.
2006 Nov 08 1:31 PM
You can create a DTD representation of your XML document using iXML at runtime. Afterwards you might include the DTD in your XML document...
2006 Nov 08 2:01 PM
hello mike,
i think i have to describe my problem more detailed.
the problem is to convert a xml source to an other xml structure. this can be done by xsl which is represented in abap by static xslt program. the transformation will be done with "call transformation".
what i want do is to create dynamical a xsl without a xslt program to transform on runtime the xml source
in this context i don´t understand your solution to use dtd for transformation. i gather the dtd will be used by the parser to validate a xml source!?
2006 Nov 08 2:13 PM
Ok, Sebastian, how should a program work that receives a XML of unknown structure and converts it into another unknown structure?
2006 Nov 08 2:58 PM
hello mike,
you are right, a program can´t convert a crystal bowl to another one
my xml source is defined by a dtd. the destination structure is defined also, but without a dtd. the destination xml structure is defined in a customizing table which contains some rules. the program should read this rules and create a "xml stylesheet".
kind regards and thank you for your help
sebastian
2006 Nov 27 5:21 PM
The class cl_xslt_processor contains all methods to transform a xml with a on runtime created xsl. I can´t say anything about performance or stability, but it works!