Difference between revisions of "SAP ABAP XSLT"
From SapWiki
| Line 57: | Line 57: | ||
==Attribute== | ==Attribute== | ||
* ejemplo 01 | * ejemplo 01 | ||
| − | <campoString> | + | <nowiki><campoString> |
'''<tt:attribute name="name" value-ref=".PERSONALIZADOS.PESO_NAME"/>''' | '''<tt:attribute name="name" value-ref=".PERSONALIZADOS.PESO_NAME"/>''' | ||
<tt:value ref=".PERSONALIZADOS.PESO"/> | <tt:value ref=".PERSONALIZADOS.PESO"/> | ||
</campoString> | </campoString> | ||
| − | <campoString name="Peso">24.271,366 KG</campoString> | + | <campoString name="Peso">24.271,366 KG</campoString></nowiki> |
* Ejemplo 02 | * Ejemplo 02 | ||
| − | <?xml version="1.0" encoding="ISO-8859-1"?> | + | <nowiki> <?xml version="1.0" encoding="ISO-8859-1"?> |
<RspRecuperarDocumento> | <RspRecuperarDocumento> | ||
'''<RecuperarDocumento ID="1376954087995">''' | '''<RecuperarDocumento ID="1376954087995">''' | ||
Revision as of 15:00, 31 March 2020
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.