Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * --- Test usage of a dynamically given non-workbench XSLT program
- * Class CL_XSLT_PROCESSOR is able to receive its XSLT code at runtime
- * So an XSLT doesn't necessarily to be created in the repository
- * The transformation gets a symbolic name and is available under this name on this server
- * This is only a buffering, however.
- * Just to go sure, the source code should always be provided when the XSLT is to be executed.
- report zz_test_cl_xslt_processor.
- data:
- * iXML master
- go_xml type ref to if_ixml,
- * iXML stream factory
- go_sf type ref to if_ixml_stream_factory.
- load-of-program.
- go_xml = cl_ixml=>create( ).
- go_sf = go_xml->create_stream_factory( ).
- start-of-selection.
- perform start.
- * --- Start
- form start.
- data: lo_source type ref to if_ixml_document,
- lo_result type ref to if_ixml_document,
- lo_processor type ref to cl_xslt_processor,
- lv_p type progname,
- lo_ex type ref to cx_xslt_exception.
- perform get_source changing lo_source.
- create object lo_processor.
- try.
- * Set source
- lo_processor->set_source_node( lo_source ).
- * Set result
- lo_result = go_xml->create_document( ).
- lo_processor->set_result_document( lo_result ).
- * This could be time-critical, the creation of a dynamical XSLT prog?
- perform set_transformation using lo_processor
- changing lv_p.
- * call xslt-proc
- lo_processor->run( lv_p ).
- * Display result
- call function 'SDIXML_DOM_TO_SCREEN'
- exporting
- document = lo_result
- title = 'Result of Transformation'
- exceptions
- no_document = 1
- others = 2.
- catch cx_xslt_exception into lo_ex.
- message lo_ex type 'I'.
- endtry.
- endform. "start
- * --- Set XSLT transformation from stream
- form set_transformation using io_processor type ref to cl_xslt_processor
- changing cv_p type progname.
- data: lo_trans type ref to if_ixml_istream.
- * sv_p contains temp. name of XSLT program after first call
- statics: sv_p type string.
- if sv_p is initial.
- * It seems that the name can be buffered on appserver level?
- import progname to sv_p
- from shared buffer indx(zx) id 'ZZ_TEST_XSLT_PROC'.
- if sv_p is initial.
- sv_p = 'X'.
- endif.
- endif.
- * Provide the stream containing the XSLT document (as a stream)
- perform get_transformation changing lo_trans.
- * Set transformation
- io_processor->set_source_stream( exporting stream = lo_trans
- changing p = sv_p ).
- * Buffer progname on server - seems to work
- export progname from sv_p
- to shared buffer indx(zx) id 'ZZ_TEST_XSLT_PROC'.
- * string -> c move necessary, since xslt-proc-interface doesn't use
- * the generic type csequence for program name
- cv_p = sv_p.
- endform. "set_transformation
- * --- Parse a source given as string into an if_ixml_document
- form get_source changing co_src type ref to if_ixml_document.
- data: lv_s type string,
- lo_stream type ref to if_ixml_istream,
- lo_parser type ref to if_ixml_parser.
- concatenate
- `<?xml version="1.0" encoding="iso-8859-1" ?>`
- `<root>2</root>`
- into lv_s.
- * Create and parse the input document as if_ixml_document
- lo_stream = go_sf->create_istream_string( lv_s ).
- co_src = go_xml->create_document( ).
- lo_parser = go_xml->create_parser( document = co_src
- istream = lo_stream
- stream_factory = go_sf ).
- lo_parser->parse( ).
- endform. "get_source
- * --- Put the transformation given as string into an if_ixml_istrean
- form get_transformation changing co_trans type ref to if_ixml_istream.
- data: lv_s type string.
- concatenate
- `<xsl:transform version="1.0"`
- ` xmlns:xsl="http://www.w3.org/1999/XSL/Transform">`
- ` <xsl:template match="root">`
- ` <GotNumber><xsl:value-of select="."/></GotNumber>`
- ` </xsl:template>`
- `</xsl:transform>`
- into lv_s.
- co_trans = go_sf->create_istream_string( lv_s ).
- endform. "get_transformation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement