XML

From Commander4j

This page is not intended to be a tutorial on XML and XSL, there are many resources online which can do that. This document is designed to illustrate how the middleware application can be used to transform an input XML document into a modified output document.

The XML connector is perhaps one of the simpler ones to explain. The core middleware application is designed to process data once it has been converted into an xml document internally. For example the CSV and ASCII connectors will load the appropriate file type and convert into XML internally so that you can manipulate the data using XSLT. The XML connector does not need to convert the raw data into XML as it's already in that format when its loaded.

In the configuration shown below you will see that an XSTL transformation is applied in the input stage, however in this example the XSLT could have been applied on the output stage without any effect on the result.

XML Map Configuration

config.xml

<map id="map107" enabled="Y" description="C4J Production Declaration to B2MML S95 XML Production Declaration">
  <input id="in1" description="Read C4J Prod Dec XML">
      <type>XML</type>
      <path>./interface/input/107 (NES C4J Production Declaration)</path>
      <mask/>
      <pollingInterval>1000</pollingInterval>
      <XSLT>C4J_PRODDEC_XML_to_S95_PRODDEC_XML.xsl</XSLT>
  </input>
  <output id="out1" enabled="Y" description="Write B2MML S95 XML Prod Dec">
      <path>./interface/output/107 (NES B2MML S95 XML Production Declaration)</path>
      <type>XML</type>
      <XSLT/>
  </output>
 </map>

Example Input Document

 <?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>WISBECH</location>
            <name>Wisbech</name>
            <gln>0000000000123</gln>
            <plant>1234</plant>
            <warehouse>789</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>

Example Output Document

 <?xml version="1.0" encoding="UTF-8"?>
 <ProductionPerformance xmlns:c4j="http://www.commander4j.com">
   <ID>12584314</ID>
   <Plant>1234</Plant>
   <PublishedDate>2024-04-12T09:39:27</PublishedDate>
   <ProductionRequestID>20725187</ProductionRequestID>
   <Recipe>100000000028949253</Recipe>
   <MaterialDefinitionID>000000000043170672</MaterialDefinitionID>
   <MaterialLotID>6214093310</MaterialLotID>
   <MaterialSubLotID>00000000000000000123</MaterialSubLotID>
   <Plant>1234</Plant>
   <Warehouse>789</Warehouse>
   <Type>PRO</Type>
   <Section/>
   <Bin>DESPATCH</Bin>
   <Quantity>5616.000</Quantity>
   <UnitOfMeasure>EA</UnitOfMeasure>
 </ProductionPerformance>

XSLT

C4J_PRODDEC_XML_to_S95_PRODDEC_XML.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" exclude-result-prefixes="xs" version="2.0">
  <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
  <xsl:strip-space elements="*"/>
  <!-- Local Variables -->
  <xsl:variable name="DATENOW" select="current-dateTime()"/>
  <xsl:variable name="MESSAGEDATE" select="format-dateTime($DATENOW, '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]')"/>
  <xsl:template match="message">
  <ProductionPerformance>
    <ID><xsl:value-of select="/message/messageRef"/></ID>
    <Plant><xsl:value-of select="/message/messageData/productionDeclaration/plant"/></Plant>
    <PublishedDate><xsl:value-of select="$MESSAGEDATE"/></PublishedDate>
    <ProductionRequestID><xsl:value-of select="/message/messageData/productionDeclaration/processOrder"/>  </ProductionRequestID>
    <Recipe><xsl:value-of select="/message/messageData/productionDeclaration/recipe"/></Recipe>
    <MaterialDefinitionID><xsl:value-of select="/message/messageData/productionDeclaration/material"/>   </MaterialDefinitionID>
    <MaterialLotID><xsl:value-of select="/message/messageData/productionDeclaration/batch"/></MaterialLotID>
    <MaterialSubLotID>00<xsl:value-of select="/message/messageData/productionDeclaration/SSCC"/></MaterialSubLotID>
    <Plant><xsl:value-of select="/message/messageData/productionDeclaration/plant"/></Plant>
    <Warehouse><xsl:value-of select="/message/messageData/productionDeclaration/warehouse"/></Warehouse>
    <Type><xsl:value-of select="/message/messageData/productionDeclaration/storageType"/></Type>
    <Section><xsl:value-of select="/message/messageData/productionDeclaration/storageSection"/></Section>
    <Bin><xsl:value-of select="/message/messageData/productionDeclaration/storageBin"/></Bin>
    <Quantity><xsl:value-of select="/message/messageData/productionDeclaration/productionQuantity"/></Quantity>
    <UnitOfMeasure><xsl:value-of select="/message/messageData/productionDeclaration/productionUOM"/></UnitOfMeasure>
  </ProductionPerformance>
  </xsl:template>
 </xsl:stylesheet>