ASCII: Difference between revisions

From Commander4j
Created page with "See Example Configuration for more information on the ASCII Input option. The ASCII Connector can be used for input and output. # ASCII Input Map Configuration **config.xml** <map id="Map02" enabled="Y" description="ASCII File Fixed Column to XML"> <input id="in1" description="Read ASCII Flat File"> <type>ASCII</type> <path>./interface/input/Map02 ASCII to XML</path> <mask/> <inputPattern>1-4,18-21</input..."
 
No edit summary
Line 15: Line 15:
             <XSLT>Map02_ASCII_to_XML.xsl</XSLT>
             <XSLT>Map02_ASCII_to_XML.xsl</XSLT>
         </input>
         </input>
         <output id="out1" enabled="Y" description="Write XML">
         <output id="out1" enabled="Y" description="Write XML">
             <path>./interface/output/Map02 ASCII to XML</path>
             <path>./interface/output/Map02 ASCII to XML</path>
Line 37: Line 36:
             <XSLT>Map09_XML_to_ASCII.xsl</XSLT>
             <XSLT>Map09_XML_to_ASCII.xsl</XSLT>
         </input>
         </input>
         <output id="out1" enabled="Y" description="Write ASCII File">
         <output id="out1" enabled="Y" description="Write ASCII File">
             <path>./interface/output/Map09 XML to ASCII</path>
             <path>./interface/output/Map09 XML to ASCII</path>
Line 58: Line 56:
   xmlns:c4j_XSLT_Ext="http://com.commander4j.Transformation"
   xmlns:c4j_XSLT_Ext="http://com.commander4j.Transformation"
   exclude-result-prefixes="xs c4j c4j_XSLT_Ext"  version="2.0">
   exclude-result-prefixes="xs c4j c4j_XSLT_Ext"  version="2.0">
 
   <xsl:output encoding="UTF-8" indent='yes' method="xml" />
   <xsl:output encoding="UTF-8" indent='yes' method="xml" />
   <xsl:strip-space  elements="*"/>
   <xsl:strip-space  elements="*"/>
   <xsl:template match="text() | @*"/>
   <xsl:template match="text() | @*"/>
   <xsl:variable name="sscc" select="/message/messageData[1]/productionDeclaration[1]/SSCC"/>
   <xsl:variable name="sscc" select="/message/messageData[1]/productionDeclaration[1]/SSCC"/>
   <xsl:template match="message/messageData/productionDeclaration">
   <xsl:template match="message/messageData/productionDeclaration">
     <data cols="15" rows="1" type="CSV">
     <data cols="15" rows="1" type="CSV">
     <row id="1">
     <row id="1">
       <col id="1"><xsl:value-of select="processOrder"/></col>
       <col id="1"><xsl:value-of select="processOrder"/></col>
       <col id="2"><xsl:value-of select="material"/></col>
       <col id="2"><xsl:value-of select="material"/></col>
Line 73: Line 68:
       <col id="4"><xsl:value-of select="floor(number(productionQuantity))"/></col>
       <col id="4"><xsl:value-of select="floor(number(productionQuantity))"/></col>
       <col id="5"><xsl:value-of select='name' /></col>
       <col id="5"><xsl:value-of select='name' /></col>
     
       <col id="6"><xsl:value-of select="c4j_XSLT_Ext:formatDate(productionDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')"/></col>
       <col id="6"><xsl:value-of select="c4j_XSLT_Ext:formatDate(productionDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')"/></col>
       <col id="7"><xsl:value-of select="batch"/></col>
       <col id="7"><xsl:value-of select="batch"/></col>
       <col id="8"><xsl:value-of select="SSCC"/></col>
       <col id="8"><xsl:value-of select="SSCC"/></col>
       <col id="9"><xsl:value-of select="c4j_XSLT_Ext:formatDate(expiryDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')" /></col>
       <col id="9"><xsl:value-of select="c4j_XSLT_Ext:formatDate(expiryDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')" /></col>
     
       <col id="10"><xsl:value-of select="warehouse"/></col>
       <col id="10"><xsl:value-of select="warehouse"/></col>
     
       <col id="11"><xsl:value-of select="storageLocation"/></col>
       <col id="11"><xsl:value-of select="storageLocation"/></col>
       <col id="12"><xsl:value-of select="c4j_XSLT_Ext:formatDate(expiryDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')" /></col>
       <col id="12"><xsl:value-of select="c4j_XSLT_Ext:formatDate(expiryDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')" /></col>

Revision as of 19:03, 23 August 2024

See Example Configuration for more information on the ASCII Input option.

The ASCII Connector can be used for input and output.

  1. ASCII Input Map Configuration
    • config.xml**
   <map id="Map02" enabled="Y" description="ASCII File Fixed Column to XML">
       <input id="in1" description="Read ASCII Flat File">
           <type>ASCII</type>
           <path>./interface/input/Map02 ASCII to XML</path>
           <mask/>
           <inputPattern>1-4,18-21</inputPattern>
           <pollingInterval>1000</pollingInterval>
           <XSLT>Map02_ASCII_to_XML.xsl</XSLT>
       </input>
       <output id="out1" enabled="Y" description="Write XML">
           <path>./interface/output/Map02 ASCII to XML</path>
           <type>XML</type>
           <XSLT/>
       </output>
   </map>

The unique setting which is important above is the `<inputPattern>1-4,18-21</inputPattern>`. This determines the columns within the input file which are to be read into memory and optionally processed by the XSLT Style Sheet.

The above scenario is documented in some detail within the Example Configuration page.

  1. ASCII Map Output Configuration
   <map id="Map09" enabled="Y" description="XML to ASCII Flat File">
       <input id="in1" description="Read XML File">
           <type>XML</type>
           <path>./interface/input/Map09 XML to ASCII</path>
           <mask/>
           <pollingInterval>1000</pollingInterval>
           <XSLT>Map09_XML_to_ASCII.xsl</XSLT>
       </input>
       <output id="out1" enabled="Y" description="Write ASCII File">
           <path>./interface/output/Map09 XML to ASCII</path>
           <type>ASCII</type>
           <outputPattern>1-10,12-21,23-53</outputPattern>
           <XSLT/>
       </output>
   </map>


The output connector is very similar to configure and in this example we use a XSL file called to create a Flat ASCII file from a standard Commander4j XML message. The XSL source in this example looks like this. In this scenario we want to extract and export the order, material and description from the xml and write to a flat ascii file. We are going to write the data to 3 column ranges define in `<outputPattern>1-10,12-21,23-53</outputPattern>`

    1. Sample XSL File

Map09_XML_to_ASCII.xsl

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:c4j="http://www.commander4j.com"
 xmlns:c4j_XSLT_Ext="http://com.commander4j.Transformation"
 exclude-result-prefixes="xs c4j c4j_XSLT_Ext"  version="2.0">
 <xsl:output encoding="UTF-8" indent='yes' method="xml" />
 <xsl:strip-space  elements="*"/>
 <xsl:template match="text() | @*"/>
 <xsl:variable name="sscc" select="/message/messageData[1]/productionDeclaration[1]/SSCC"/>
 <xsl:template match="message/messageData/productionDeclaration">
   
   <row id="1">
     <col id="1"><xsl:value-of select="processOrder"/></col>
     <col id="2"><xsl:value-of select="material"/></col>
     <col id="3"><xsl:value-of select="c4j_XSLT_Ext:removeCommas(description)"/></col>
     <col id="4"><xsl:value-of select="floor(number(productionQuantity))"/></col>
     <col id="5"><xsl:value-of select='name' /></col>
     <col id="6"><xsl:value-of select="c4j_XSLT_Ext:formatDate(productionDate, 'yyyy-MM-ddTHH:mm', 'dd-MMM-yyyy')"/></col>
     <col id="7"><xsl:value-of select="batch"/></col>
     <col id="8"><xsl:value-of select="SSCC"/></col>
     <col id="9"><xsl:value-of select="c4j_XSLT_Ext:formatDate(expiryDate, 'yyyy-MM-ddTHH:mm', 'dd-MMM-yyyy')" /></col>
     <col id="10"><xsl:value-of select="warehouse"/></col>
     <col id="11"><xsl:value-of select="storageLocation"/></col>
     <col id="12"><xsl:value-of select="c4j_XSLT_Ext:formatDate(expiryDate, 'yyyy-MM-ddTHH:mm', 'dd-MMM-yyyy')" /></col>
     <col id="13"><xsl:value-of select="c4j_XSLT_Ext:formatDate(productionDate, 'yyyy-MM-ddTHH:mm', 'dd-MMM-yyyy')"/></col>
     <col id="14"><xsl:value-of select="old_code"/></col>
     <col id="15"><xsl:value-of select="c4j_XSLT_Ext:subString($sscc, 8, 9)"/></col>
   </row>
        
 </xsl:template>
</xsl:stylesheet>


The above style sheet creates a intermediate XML file which is then passed to the ASCII connector to write the flat file. It is important to match the number of columns extracted with the XSL to the number of columns defined in the output connector. You will notice that the XSL includes some functions. The description for example uses a function to remove commas. You can find more information regardin these functions in XSLT Extension Functions

Lets work through the sample files to understand what is happening here.

    1. Sample XML Input File (Commander4j Production Declaration message)

XML to ASCII Flat File 1.xml

<?xml version="1.0" encoding="UTF-8"?>
<message>
   <hostRef>service</hostRef>
   <messageRef>12584314</messageRef>
   <interfaceType>Production Declaration</interfaceType>
   <messageInformation>SSCC=000000000000000123</messageInformation>
   <interfaceDirection>Output</interfaceDirection>
   <messageDate>2016-08-01T14:58:16</messageDate>
   <messageData>
       <productionDeclaration>
           <SSCC>000000000000000123</SSCC>
           <processOrder>20725187</processOrder>
           <recipe>100000000028949253</recipe>
           <requiredResource>P2VK1112</requiredResource>
           <material>43170672</material>
           <description>Self Sealing Stem Bolt</description>
           <old_code/>
           <ean>07613032213848</ean>
           <variant>00</variant>
           <status>Unrestricted</status>
           <batch>6214093310</batch>
           <batchStatus>Restricted</batchStatus>
           <expiry_Mode>BATCH</expiry_Mode>
           <expiryDate>2018-08-31T00:00:00</expiryDate>
           <location>EARTH</location>
           <name>Earth</name>
           <gln>5000161800292</gln>
           <plant>0933</plant>
           <warehouse>734</warehouse>
           <storageLocation>0001</storageLocation>
           <storageSection/>
           <storageBin>DESPATCH</storageBin>
           <storageType>PRO</storageType>
           <productionQuantity>5616.000</productionQuantity>
           <productionUOM>EA</productionUOM>
           <confirmed>Y</confirmed>
           <productionDate>2016-08-01T14:58:03</productionDate>
       </productionDeclaration>
   </messageData>
</message>


    1. Intermediate XML (result of appling XSL to input XML message)
<?xml version="1.0" encoding="UTF-8"?>

  <row id="1">
     <col id="1">20725187</col>
     <col id="2">43170672</col>
     <col id="3">Self Sealing Stem Bolt</col>
     <col id="4">5616</col>
     <col id="5">Earth</col>
     <col id="6">01-Aug-2016</col>
     <col id="7">6214093310</col>
     <col id="8">000000000000000123</col>
     <col id="9">31-Aug-2018</col>
     <col id="10">734</col>
     <col id="11">0001</col>
     <col id="12">31-Aug-2018</col>
     <col id="13">01-Aug-2016</col>
     <col id="14"/>
     <col id="15">000000012</col>
  </row>

When the XSL executed against the input XML the above intermediate file is created. This is then passed to the output connector which matches the data found in the xml above to the column definitions.

    1. Output ASCII
20725187   43170672   Self Sealing Stem Bolt         


This is the output from the transformation. The intermediate files can be found in the interface/log directory. For more information see the Example Configuration