Transforming XML file into fixed length flat file in SAP

This is an EDIfact invoice. Try using the script, and it can help −
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="text" encoding="ISO-8859-1"/>
   <xsl:template match="/">
   <!-- EDI_DC40 -->
   <xsl:for-each select="IDataXMLCoder/record/idatacodable/array/idatacodable/record/value">
      <xsl:value-of select="text()"/>
      <xsl:choose>
         <!-- TABNAM (10) -->
         <xsl:when test="@name = 'TABNAM'">
            <xsl:choose>
               <xsl:when test="string-length(text()) = 0">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 1">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 2">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 3">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 4">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 5">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 6">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 7">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 8">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 9">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) &gt; 10">
                  <xsl:message terminate="yes">ERROR: The maximum length of "TABNAM" is 10 characters.</xsl:message>
               </xsl:when>
               <xsl:otherwise/>
            </xsl:choose>
         </xsl:when>
         <!-- MANDT (3)-->
         <xsl:when test="MANDT">
            <xsl:choose>
               <xsl:when test="string-length(text()) = 0">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 1">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) = 2">
                  <xsl:text></xsl:text>
               </xsl:when>
               <xsl:when test="string-length(text()) &gt; 3">
                  <xsl:message terminate="yes">ERROR: The maximum length of "MANDT" is 3 characters.</xsl:message>
               </xsl:when>
               <xsl:otherwise/>
            </xsl:choose>
         </xsl:when>
         <!-- DOCNUM (16) -->
         <!-- DOCREL (4) -->
         <!-- STATUS (4) -->
         <!-- etc. -->
      </xsl:choose>
      </xsl:for-each>
      <xsl:text>&#x0D;&#x0A;</xsl:text>
      <!-- E1EDK01 -->
      <xsl:for-each select="IDataXMLCoder/record/idatacodable/array/idatacodable/array/idatacodable/record/value">
         <xsl:value-of select="text()"/>
         <xsl:choose>
            <!-- ACTION (3) -->
            <xsl:when test="@name = 'ACTION'">
               <xsl:choose>
                  <xsl:when test="string-length(text()) = 0">
                     <xsl:text></xsl:text>
                  </xsl:when>
                  <xsl:when test="string-length(text()) = 1">
                     <xsl:text></xsl:text>
                  </xsl:when>
                  <xsl:when test="string-length(text()) = 2">
                     <xsl:text></xsl:text>
                  </xsl:when>
                  <xsl:when test="string-length(text()) &gt; 3">
                     <xsl:message terminate="yes">ERROR: The maximum length of "ACTION" is 3 characters.</xsl:message>
                  </xsl:when>
                  <xsl:otherwise/>
               </xsl:choose>
            </xsl:when>
            <!-- KZABS (1)-->
            <xsl:when test="KZABS">
               <xsl:choose>
                  <xsl:when test="string-length(text()) = 0">
                     <xsl:text></xsl:text>
                  </xsl:when>
                  <xsl:when test="string-length(text()) &gt; 1">
                     <xsl:message terminate="yes">ERROR: The maximum length of "KZABS" is 1 character.</xsl:message>
                  </xsl:when>
                  <xsl:otherwise/>
               </xsl:choose>
            </xsl:when>
            <!-- CURCY (3) -->
            <!-- HWAER (3) -->
            <!-- WKURS (12) -->
            <!-- etc. -->
         </xsl:choose>
      </xsl:for-each>
   </xsl:template>
</xsl:stylesheet>
There are various sites which provide a built-in script to convert your EDIfact to XSLT.  Check this site and it may also help −
https://www.codeproject.com/Articles/11278/EDIFACT-to-XML-to-Anything-You-Want