[{ALLOW view All}]
[{ALLOW edit Authenticated}]

Transforming a file into another file

1. transaction STRANS
2. tranformation <your_transformation> > Create as XSLT program / Change
3. edit and copy all your filter into the match Person template like:
    <xsl:if test=
"PersonNumber='123456' or
PersonNumber='AB_987'"
>
4. report SXSLT_TEST (variant TEST_ME)
	Transformation = <your_transformation>
	Source File Path = Path and filename to your source XML
	Result File Path = Path and filename of your result XML
5. Click "Output to File"
Note 1: you can check first with button "View HTML"
Note 2: result file is serialized, to pretty print you need to use a tool like notepad++


transformation ZHCM_WORKER_PERNR_FILTER (as XSLT program)
{{{
<xsl:transform version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:sap="http://www.sap.com/sapxsl">
  <xsl:strip-space elements="*"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="Person">
    <xsl:if test=
"PersonNumber='123456' or
PersonNumber='AB_987'"
>
      <xsl:copy-of select="."/>
    </xsl:if>

  </xsl:template>
</xsl:transform>
}}}
----
For accessing __XML__ documents use
[iXML|http://help.sap.com/saphelp_nw04/helpdata/en/86/8280cc12d511d5991b00508b6b8b11/frameset.htm]

For __XSLT__ you can create a "Transformation". \\
1. Object Navigator > Right Click Package > Create > Other (1) > Transformation \\
(This opens an XSLT editor, you can use also transaction STRANS)

2. Write down your XSLT specs

3. Activate it (!)

4. Test it (F8)\\
(This will use program "SXSLT_TEST", here you can look how to do it in ABAP)

5. Write a small program to automate transformation from one file to another
{{{
*&---------------------------------------------------------------------*
*& Report  Y_IXML001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Y_IXML001.

Data: g_ixml type ref to if_ixml,
      streamFactory type ref to if_ixml_stream_factory,
      iStream type ref to if_ixml_istream,
      oStream type REF TO IF_IXML_OSTREAM,
      xmlRes type string,
      out type string.

type-pools: ixml.
class cl_ixml definition load.

g_ixml = cl_ixml=>create( ).

streamFactory = g_ixml->create_stream_factory( ).

iStream = streamFactory->create_istream_uri( 'file://e:\sap\test.xml' ).
oStream = streamFactory->create_ostream_uri( 'file://e:\sap\result.xml' ).

CALL TRANSFORMATION Y_TRANS001
  SOURCE XML iStream
  RESULT XML oStream.

write 'Done.'.
}}}