SAP ABAP XSLT
From SapWiki
Revision as of 14:37, 4 April 2020 by WikiSysop (talk | contribs) (→Ejemplo 01: XSLT ZHCM_CARGAR_DOCUMENTO (trn. xslt_tool))
Contents
Ejemplo 01: XSLT ZHCM_CARGAR_DOCUMENTO (trn. xslt_tool)
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<documento>
<id_documento tt:value-ref=".ROOT.ID_DOCUMENTO"/>
<tt:cond check="not-initial(ROOT.FIRMA)">
<firma tt:value-ref=".ROOT.FIRMA"/>
</tt:cond>
<nombre_documento tt:value-ref=".ROOT.NOMBRE_DOCUMENTO"/>
<tipo_archivo tt:value-ref=".ROOT.TIPO_ARCHIVO"/>
<archivo_b64 tt:value-ref=".ROOT.ARCHIVO_B64"/>
</documento>
</tt:template>
</tt:transform>
Generar XML
types: begin of ty_documento,
ID_DOCUMENTO type string,
firma type string,
NOMBRE_DOCUMENTO type string,
TIPO_ARCHIVO type string,
ARCHIVO_B64 type string,
end of ty_documento.
data ls_documento type ty_documento.
data l_documento_xml type string.
DATA l_exception_error TYPE REF TO cx_st_error.
DATA l_st_error TYPE string.
TRY.
CALL TRANSFORMATION zhcm_cargar_documento
SOURCE root = ls_documento
RESULT XML l_documento_xml.
CATCH cx_st_error INTO l_exception_error.
l_st_error = l_exception_error->get_text( ).
p_subrc = 1.
p_msg = l_st_error.
RETURN.
ENDTRY.
Leer XML
DATA l_exception_error TYPE REF TO cx_st_error.
DATA l_st_error TYPE string.
TRY.
CALL TRANSFORMATION zhcm_cargar_documento
SOURCE XML l_documento_xml
RESULT root = ls_documento.
CATCH cx_st_error INTO l_exception_error.
l_st_error = l_exception_error->get_text( ).
p_subrc = 1.
p_msg = l_st_error.
RETURN.
ENDTRY.
Attribute
- ejemplo 01
<campoString> <tt:attribute name="name" value-ref=".PERSONALIZADOS.PESO_NAME"/> <tt:value ref=".PERSONALIZADOS.PESO"/> </campoString> <campoString name="Peso">24.271,366 KG</campoString>
- Ejemplo 02
<?xml version="1.0" encoding="ISO-8859-1"?>
<RspRecuperarDocumento>
<RecuperarDocumento ID="1376954087995">
<EstadoOperacion>0</EstadoOperacion>
<Mensaje>Operación existosa</Mensaje>
<idExpediente>413</idExpediente>
<Documento>
<idDocumento>697</idDocumento>
<Extension>PDF</Extension>
<Formato>base64</Formato>
<CodTipoDocumento>1</CodTipoDocumento>
<Data>R0lGODlh3QAxAPcAAAAA</Data>
</Documento>
</RecuperarDocumento>
</RspRecuperarDocumento>
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="RSPRECUPERARDOCUMENTO"/>
<tt:template>
<RspRecuperarDocumento>
<RecuperarDocumento>
<tt:attribute name="ID" value-ref=".RSPRECUPERARDOCUMENTO.IDRECUPERARDOCUMENTO"/>
<EstadoOperacion tt:value-ref=".RSPRECUPERARDOCUMENTO.ESTADOOPERACION"/>
<Mensaje tt:value-ref=".RSPRECUPERARDOCUMENTO.MENSAJE"/>
<tt:cond check="not-initial(RSPRECUPERARDOCUMENTO.IDEXPEDIENTE)">
<idExpediente tt:value-ref=".RSPRECUPERARDOCUMENTO.IDEXPEDIENTE"/>
</tt:cond>
<tt:cond check="not-initial(RSPRECUPERARDOCUMENTO.DATA)">
<Documento>
<idDocumento tt:value-ref=".RSPRECUPERARDOCUMENTO.IDDOCUMENTO"/>
<Extension tt:value-ref=".RSPRECUPERARDOCUMENTO.EXTENCION"/>
<Formato tt:value-ref=".RSPRECUPERARDOCUMENTO.FORMATO"/>
<CodTipoDocumento tt:value-ref=".RSPRECUPERARDOCUMENTO.CODTIPODOCUMENTO"/>
<Data tt:value-ref=".RSPRECUPERARDOCUMENTO.DATA"/>
</Documento>
</tt:cond>
</RecuperarDocumento>
</RspRecuperarDocumento>
</tt:template>
</tt:transform>
Cond
<tt:cond check="not-initial(RSPCONSULTAREXPEDIENTE.RUTEMPLEADOR)"> <RUTEMPLEADOR tt:value-ref=".RSPCONSULTAREXPEDIENTE.RUTEMPLEADOR"/> </tt:cond>
Ver XML DISPLAY_XML_STRING
data l_xtring type xstring.
try.
CALL TRANSFORMATION Z_TRANSF_SIMPLE_EJEMPLO1
SOURCE ROOT = t_a
RESULT XML l_xstring.
catch cx_st_error.
endtry.
call function 'DISPLAY_XML_STRING' EXPORTING xml_string = l_xstring.