<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.commander4j.com/index.php?action=history&amp;feed=atom&amp;title=Creating_a_Map</id>
	<title>Creating a Map - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.commander4j.com/index.php?action=history&amp;feed=atom&amp;title=Creating_a_Map"/>
	<link rel="alternate" type="text/html" href="https://wiki.commander4j.com/index.php?title=Creating_a_Map&amp;action=history"/>
	<updated>2026-11-23T06:34:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.commander4j.com/index.php?title=Creating_a_Map&amp;diff=2013&amp;oldid=prev</id>
		<title>Dgarratt: Updated by push_wiki.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.commander4j.com/index.php?title=Creating_a_Map&amp;diff=2013&amp;oldid=prev"/>
		<updated>2026-11-09T20:47:20Z</updated>

		<summary type="html">&lt;p&gt;Updated by push_wiki.py&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page shows how to build a new [[Maps|map]] for [[Middleware4j]] from nothing, using a small worked example. Read [[Overview Middleware4j]] first if you have not already: it explains the three parts of a map.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 INPUT CONNECTOR  --XML--&amp;gt;  MAP (XSLT)  --XML--&amp;gt;  OUTPUT CONNECTOR(S)&lt;br /&gt;
 native to XML              XML to XML            XML to native&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building a map always follows the same five steps:&lt;br /&gt;
&lt;br /&gt;
# Choose the input connector for the file you receive.&lt;br /&gt;
# Run a sample file through it and look at the XML it produces.&lt;br /&gt;
# Look up the XML layout that your output connector expects.&lt;br /&gt;
# Write a stylesheet that turns the first into the second.&lt;br /&gt;
# Add the stylesheet to the map and test it.&lt;br /&gt;
&lt;br /&gt;
== The example ==&lt;br /&gt;
&lt;br /&gt;
A supplier system writes purchase orders as a CSV file. Two things are needed from each file: an XML document for one system, and a fixed column text file for an older one.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;orders.csv&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PO10001,43170672,&amp;quot;Stem Bolt, Self Sealing&amp;quot;,120,EA,31/08/2026&lt;br /&gt;
PO10002,43170673,Reverse Ratchet,40,CS,15/09/2026&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One input format and two outputs means one map with a [[CSV]] input connector, an [[XML]] output connector and an [[ASCII]] output connector.&lt;br /&gt;
&lt;br /&gt;
== Step 1: add the map with its input connector ==&lt;br /&gt;
&lt;br /&gt;
Create the folders first. Middleware4j checks that every input and output folder exists when it starts and reports any that are missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface/input/Orders&lt;br /&gt;
interface/output/OrdersXML&lt;br /&gt;
interface/output/OrdersFixed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then add a map to &amp;lt;code&amp;gt;xml/config/config.xml&amp;lt;/code&amp;gt;, inside the &amp;lt;code&amp;gt;&amp;amp;lt;maps&amp;amp;gt;&amp;lt;/code&amp;gt; element. To begin with it has the input connector and one plain XML output, with no stylesheet. Every setting is explained on the [[Maps]] page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;map&amp;gt;&lt;br /&gt;
   &amp;lt;id&amp;gt;Orders&amp;lt;/id&amp;gt;&lt;br /&gt;
   &amp;lt;enabled&amp;gt;true&amp;lt;/enabled&amp;gt;&lt;br /&gt;
   &amp;lt;description&amp;gt;Purchase orders CSV to XML and fixed width&amp;lt;/description&amp;gt;&lt;br /&gt;
   &amp;lt;enableEmailNotifications&amp;gt;true&amp;lt;/enableEmailNotifications&amp;gt;&lt;br /&gt;
   &amp;lt;connectors&amp;gt;&lt;br /&gt;
      &amp;lt;input&amp;gt;&lt;br /&gt;
         &amp;lt;id&amp;gt;in1&amp;lt;/id&amp;gt;&lt;br /&gt;
         &amp;lt;description&amp;gt;Read orders CSV&amp;lt;/description&amp;gt;&lt;br /&gt;
         &amp;lt;type&amp;gt;CSV&amp;lt;/type&amp;gt;&lt;br /&gt;
         &amp;lt;url&amp;gt;&lt;br /&gt;
            &amp;lt;path&amp;gt;./interface/input/Orders&amp;lt;/path&amp;gt;&lt;br /&gt;
            &amp;lt;mask/&amp;gt;&lt;br /&gt;
            &amp;lt;prefix/&amp;gt;&lt;br /&gt;
            &amp;lt;pollingInterval&amp;gt;1000&amp;lt;/pollingInterval&amp;gt;&lt;br /&gt;
         &amp;lt;/url&amp;gt;&lt;br /&gt;
         &amp;lt;csv&amp;gt;&lt;br /&gt;
            &amp;lt;optionDelimeter&amp;gt;^&amp;lt;/optionDelimeter&amp;gt;&lt;br /&gt;
            &amp;lt;csvOptions&amp;gt;separator=,^quote=&amp;quot;&amp;lt;/csvOptions&amp;gt;&lt;br /&gt;
         &amp;lt;/csv&amp;gt;&lt;br /&gt;
      &amp;lt;/input&amp;gt;&lt;br /&gt;
      &amp;lt;output&amp;gt;&lt;br /&gt;
         &amp;lt;id&amp;gt;out1&amp;lt;/id&amp;gt;&lt;br /&gt;
         &amp;lt;enabled&amp;gt;true&amp;lt;/enabled&amp;gt;&lt;br /&gt;
         &amp;lt;description&amp;gt;Write orders XML&amp;lt;/description&amp;gt;&lt;br /&gt;
         &amp;lt;type&amp;gt;XML&amp;lt;/type&amp;gt;&lt;br /&gt;
         &amp;lt;url&amp;gt;&lt;br /&gt;
            &amp;lt;path&amp;gt;./interface/output/OrdersXML&amp;lt;/path&amp;gt;&lt;br /&gt;
            &amp;lt;prefix/&amp;gt;&lt;br /&gt;
            &amp;lt;fileExtension/&amp;gt;&lt;br /&gt;
            &amp;lt;use83GUID&amp;gt;false&amp;lt;/use83GUID&amp;gt;&lt;br /&gt;
            &amp;lt;retainOriginalFilename&amp;gt;false&amp;lt;/retainOriginalFilename&amp;gt;&lt;br /&gt;
         &amp;lt;/url&amp;gt;&lt;br /&gt;
      &amp;lt;/output&amp;gt;&lt;br /&gt;
   &amp;lt;/connectors&amp;gt;&lt;br /&gt;
&amp;lt;/map&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: see what the input connector produces ==&lt;br /&gt;
&lt;br /&gt;
Start Middleware4j in desktop mode, press &amp;#039;&amp;#039;&amp;#039;Start&amp;#039;&amp;#039;&amp;#039;, and copy &amp;lt;code&amp;gt;orders.csv&amp;lt;/code&amp;gt; into &amp;lt;code&amp;gt;interface/input/Orders&amp;lt;/code&amp;gt;. Within a second the file disappears from the input folder.&lt;br /&gt;
&lt;br /&gt;
Now look in &amp;lt;code&amp;gt;interface/log&amp;lt;/code&amp;gt;. There is a file whose name contains &amp;lt;code&amp;gt;_XSLT_INPUT_&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
20261109203242991_XSLT_INPUT_Orders_in1_CSV_orders.csv.xml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the XML the input connector made from the CSV file, and it is exactly what your stylesheet will receive. Laid out for reading, it looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;data cols=&amp;quot;6&amp;quot; filename=&amp;quot;orders.csv&amp;quot; rows=&amp;quot;2&amp;quot; type=&amp;quot;CSV&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;row id=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;1&amp;quot;&amp;gt;PO10001&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;2&amp;quot;&amp;gt;43170672&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;3&amp;quot;&amp;gt;Stem Bolt, Self Sealing&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;4&amp;quot;&amp;gt;120&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;5&amp;quot;&amp;gt;EA&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;6&amp;quot;&amp;gt;31/08/2026&amp;lt;/col&amp;gt;&lt;br /&gt;
   &amp;lt;/row&amp;gt;&lt;br /&gt;
   &amp;lt;row id=&amp;quot;2&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;1&amp;quot;&amp;gt;PO10002&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;2&amp;quot;&amp;gt;43170673&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;3&amp;quot;&amp;gt;Reverse Ratchet&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;4&amp;quot;&amp;gt;40&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;5&amp;quot;&amp;gt;CS&amp;lt;/col&amp;gt;&lt;br /&gt;
      &amp;lt;col id=&amp;quot;6&amp;quot;&amp;gt;15/09/2026&amp;lt;/col&amp;gt;&lt;br /&gt;
   &amp;lt;/row&amp;gt;&lt;br /&gt;
&amp;lt;/data&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the map has no stylesheet yet, the same XML has also been written to &amp;lt;code&amp;gt;interface/output/OrdersXML&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is the quickest way to learn what any input connector gives you: run a real file through it and read the result. The layouts are also listed on the [[Connectors]] page.&lt;br /&gt;
&lt;br /&gt;
== Step 3: find the layout the output connector expects ==&lt;br /&gt;
&lt;br /&gt;
Each output connector reads XML in one particular layout. They are all listed in [[Connectors#What each output connector expects|What each output connector expects]]. For this example:&lt;br /&gt;
&lt;br /&gt;
* The &amp;#039;&amp;#039;&amp;#039;XML&amp;#039;&amp;#039;&amp;#039; output connector writes whatever XML it is given, so the stylesheet can produce any layout the receiving system wants.&lt;br /&gt;
* The &amp;#039;&amp;#039;&amp;#039;ASCII&amp;#039;&amp;#039;&amp;#039; output connector expects a &amp;lt;code&amp;gt;&amp;amp;lt;data&amp;amp;gt;&amp;lt;/code&amp;gt; element with &amp;lt;code&amp;gt;rows&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cols&amp;lt;/code&amp;gt; attributes, containing numbered &amp;lt;code&amp;gt;&amp;amp;lt;row&amp;amp;gt;&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;&amp;amp;lt;col&amp;amp;gt;&amp;lt;/code&amp;gt; elements. It places each column at the positions given by the &amp;lt;code&amp;gt;&amp;amp;lt;pattern&amp;amp;gt;&amp;lt;/code&amp;gt; setting of the connector.&lt;br /&gt;
&lt;br /&gt;
== Step 4: write the stylesheets ==&lt;br /&gt;
&lt;br /&gt;
The two outputs need different XML, so each gets its own stylesheet. Save both in the &amp;lt;code&amp;gt;xslt&amp;lt;/code&amp;gt; folder.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Orders_to_XML.xsl&amp;#039;&amp;#039;&amp;#039; builds the XML document. The due date is converted from &amp;lt;code&amp;gt;31/08/2026&amp;lt;/code&amp;gt; to ISO format with one of the [[XSLT Extension Functions]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;xsl:stylesheet xmlns:xsl=&amp;quot;http://www.w3.org/1999/XSL/Transform&amp;quot;&lt;br /&gt;
	xmlns:xs=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&lt;br /&gt;
	xmlns:c4j_XSLT_Ext=&amp;quot;http://com.commander4j.Transformation&amp;quot;&lt;br /&gt;
	exclude-result-prefixes=&amp;quot;xs c4j_XSLT_Ext&amp;quot; version=&amp;quot;2.0&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;xsl:output encoding=&amp;quot;UTF-8&amp;quot; indent=&amp;quot;yes&amp;quot; method=&amp;quot;xml&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;xsl:template match=&amp;quot;/data&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;orders&amp;gt;&lt;br /&gt;
			&amp;lt;xsl:apply-templates select=&amp;quot;row&amp;quot;/&amp;gt;&lt;br /&gt;
		&amp;lt;/orders&amp;gt;&lt;br /&gt;
	&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;xsl:template match=&amp;quot;row&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;order&amp;gt;&lt;br /&gt;
			&amp;lt;number&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;col[@id=&amp;#039;1&amp;#039;]&amp;quot;/&amp;gt;&amp;lt;/number&amp;gt;&lt;br /&gt;
			&amp;lt;material&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;col[@id=&amp;#039;2&amp;#039;]&amp;quot;/&amp;gt;&amp;lt;/material&amp;gt;&lt;br /&gt;
			&amp;lt;description&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;col[@id=&amp;#039;3&amp;#039;]&amp;quot;/&amp;gt;&amp;lt;/description&amp;gt;&lt;br /&gt;
			&amp;lt;quantity&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;col[@id=&amp;#039;4&amp;#039;]&amp;quot;/&amp;gt;&amp;lt;/quantity&amp;gt;&lt;br /&gt;
			&amp;lt;uom&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;col[@id=&amp;#039;5&amp;#039;]&amp;quot;/&amp;gt;&amp;lt;/uom&amp;gt;&lt;br /&gt;
			&amp;lt;dueDate&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;c4j_XSLT_Ext:formatDate(col[@id=&amp;#039;6&amp;#039;], &amp;#039;dd/MM/yyyy&amp;#039;, &amp;#039;yyyy-MM-dd&amp;#039;&amp;#039;T&amp;#039;&amp;#039;HH:mm:ss&amp;#039;)&amp;quot;/&amp;gt;&amp;lt;/dueDate&amp;gt;&lt;br /&gt;
		&amp;lt;/order&amp;gt;&lt;br /&gt;
	&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Orders_to_Fixed.xsl&amp;#039;&amp;#039;&amp;#039; builds the rows and columns for the fixed column file. It keeps four of the six columns and pads the quantity with leading zeros.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;xsl:stylesheet xmlns:xsl=&amp;quot;http://www.w3.org/1999/XSL/Transform&amp;quot;&lt;br /&gt;
	xmlns:xs=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&lt;br /&gt;
	xmlns:c4j_XSLT_Ext=&amp;quot;http://com.commander4j.Transformation&amp;quot;&lt;br /&gt;
	exclude-result-prefixes=&amp;quot;xs c4j_XSLT_Ext&amp;quot; version=&amp;quot;2.0&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;xsl:output encoding=&amp;quot;UTF-8&amp;quot; indent=&amp;quot;yes&amp;quot; method=&amp;quot;xml&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;xsl:template match=&amp;quot;/data&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;data type=&amp;quot;ASCII&amp;quot; cols=&amp;quot;4&amp;quot; rows=&amp;quot;{count(row)}&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;xsl:for-each select=&amp;quot;row&amp;quot;&amp;gt;&lt;br /&gt;
				&amp;lt;row id=&amp;quot;{position()}&amp;quot;&amp;gt;&lt;br /&gt;
					&amp;lt;col id=&amp;quot;1&amp;quot;&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;col[@id=&amp;#039;1&amp;#039;]&amp;quot;/&amp;gt;&amp;lt;/col&amp;gt;&lt;br /&gt;
					&amp;lt;col id=&amp;quot;2&amp;quot;&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;col[@id=&amp;#039;2&amp;#039;]&amp;quot;/&amp;gt;&amp;lt;/col&amp;gt;&lt;br /&gt;
					&amp;lt;col id=&amp;quot;3&amp;quot;&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;c4j_XSLT_Ext:padStringLeft(col[@id=&amp;#039;4&amp;#039;], 8, &amp;#039;0&amp;#039;)&amp;quot;/&amp;gt;&amp;lt;/col&amp;gt;&lt;br /&gt;
					&amp;lt;col id=&amp;quot;4&amp;quot;&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;col[@id=&amp;#039;5&amp;#039;]&amp;quot;/&amp;gt;&amp;lt;/col&amp;gt;&lt;br /&gt;
				&amp;lt;/row&amp;gt;&lt;br /&gt;
			&amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;
		&amp;lt;/data&amp;gt;&lt;br /&gt;
	&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that this stylesheet does not write a text file. It writes XML rows and columns, and the ASCII output connector turns them into text.&lt;br /&gt;
&lt;br /&gt;
== Step 5: add the stylesheets and the second output ==&lt;br /&gt;
&lt;br /&gt;
Replace the &amp;lt;code&amp;gt;&amp;amp;lt;output&amp;amp;gt;&amp;lt;/code&amp;gt; section of the map with the two outputs below. Each names its stylesheet in an &amp;lt;code&amp;gt;&amp;amp;lt;xsl&amp;amp;gt;&amp;lt;/code&amp;gt; element, and the ASCII output has a &amp;lt;code&amp;gt;&amp;amp;lt;pattern&amp;amp;gt;&amp;lt;/code&amp;gt; giving the start and end position of each column.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;output&amp;gt;&lt;br /&gt;
   &amp;lt;id&amp;gt;out1&amp;lt;/id&amp;gt;&lt;br /&gt;
   &amp;lt;enabled&amp;gt;true&amp;lt;/enabled&amp;gt;&lt;br /&gt;
   &amp;lt;description&amp;gt;Write orders XML&amp;lt;/description&amp;gt;&lt;br /&gt;
   &amp;lt;type&amp;gt;XML&amp;lt;/type&amp;gt;&lt;br /&gt;
   &amp;lt;url&amp;gt;&lt;br /&gt;
      &amp;lt;path&amp;gt;./interface/output/OrdersXML&amp;lt;/path&amp;gt;&lt;br /&gt;
      &amp;lt;prefix/&amp;gt;&lt;br /&gt;
      &amp;lt;fileExtension/&amp;gt;&lt;br /&gt;
      &amp;lt;use83GUID&amp;gt;false&amp;lt;/use83GUID&amp;gt;&lt;br /&gt;
      &amp;lt;retainOriginalFilename&amp;gt;false&amp;lt;/retainOriginalFilename&amp;gt;&lt;br /&gt;
   &amp;lt;/url&amp;gt;&lt;br /&gt;
   &amp;lt;xsl&amp;gt;&lt;br /&gt;
      &amp;lt;XSLT&amp;gt;Orders_to_XML.xsl&amp;lt;/XSLT&amp;gt;&lt;br /&gt;
   &amp;lt;/xsl&amp;gt;&lt;br /&gt;
&amp;lt;/output&amp;gt;&lt;br /&gt;
&amp;lt;output&amp;gt;&lt;br /&gt;
   &amp;lt;id&amp;gt;out2&amp;lt;/id&amp;gt;&lt;br /&gt;
   &amp;lt;enabled&amp;gt;true&amp;lt;/enabled&amp;gt;&lt;br /&gt;
   &amp;lt;description&amp;gt;Write fixed width file&amp;lt;/description&amp;gt;&lt;br /&gt;
   &amp;lt;type&amp;gt;ASCII&amp;lt;/type&amp;gt;&lt;br /&gt;
   &amp;lt;url&amp;gt;&lt;br /&gt;
      &amp;lt;path&amp;gt;./interface/output/OrdersFixed&amp;lt;/path&amp;gt;&lt;br /&gt;
      &amp;lt;prefix/&amp;gt;&lt;br /&gt;
      &amp;lt;fileExtension/&amp;gt;&lt;br /&gt;
      &amp;lt;use83GUID&amp;gt;false&amp;lt;/use83GUID&amp;gt;&lt;br /&gt;
      &amp;lt;retainOriginalFilename&amp;gt;true&amp;lt;/retainOriginalFilename&amp;gt;&lt;br /&gt;
   &amp;lt;/url&amp;gt;&lt;br /&gt;
   &amp;lt;xsl&amp;gt;&lt;br /&gt;
      &amp;lt;XSLT&amp;gt;Orders_to_Fixed.xsl&amp;lt;/XSLT&amp;gt;&lt;br /&gt;
   &amp;lt;/xsl&amp;gt;&lt;br /&gt;
   &amp;lt;ascii&amp;gt;&lt;br /&gt;
      &amp;lt;pattern&amp;gt;1-10,12-19,21-28,30-32&amp;lt;/pattern&amp;gt;&lt;br /&gt;
   &amp;lt;/ascii&amp;gt;&lt;br /&gt;
&amp;lt;/output&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart Middleware4j so that it reads the changed &amp;lt;code&amp;gt;config.xml&amp;lt;/code&amp;gt;, and copy &amp;lt;code&amp;gt;orders.csv&amp;lt;/code&amp;gt; into the input folder again.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;interface/output/OrdersXML/Orders_out1_orders.csv.xml&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;orders&amp;gt;&lt;br /&gt;
   &amp;lt;order&amp;gt;&lt;br /&gt;
      &amp;lt;number&amp;gt;PO10001&amp;lt;/number&amp;gt;&lt;br /&gt;
      &amp;lt;material&amp;gt;43170672&amp;lt;/material&amp;gt;&lt;br /&gt;
      &amp;lt;description&amp;gt;Stem Bolt, Self Sealing&amp;lt;/description&amp;gt;&lt;br /&gt;
      &amp;lt;quantity&amp;gt;120&amp;lt;/quantity&amp;gt;&lt;br /&gt;
      &amp;lt;uom&amp;gt;EA&amp;lt;/uom&amp;gt;&lt;br /&gt;
      &amp;lt;dueDate&amp;gt;2026-08-31T00:00:00&amp;lt;/dueDate&amp;gt;&lt;br /&gt;
   &amp;lt;/order&amp;gt;&lt;br /&gt;
   &amp;lt;order&amp;gt;&lt;br /&gt;
      &amp;lt;number&amp;gt;PO10002&amp;lt;/number&amp;gt;&lt;br /&gt;
      &amp;lt;material&amp;gt;43170673&amp;lt;/material&amp;gt;&lt;br /&gt;
      &amp;lt;description&amp;gt;Reverse Ratchet&amp;lt;/description&amp;gt;&lt;br /&gt;
      &amp;lt;quantity&amp;gt;40&amp;lt;/quantity&amp;gt;&lt;br /&gt;
      &amp;lt;uom&amp;gt;CS&amp;lt;/uom&amp;gt;&lt;br /&gt;
      &amp;lt;dueDate&amp;gt;2026-09-15T00:00:00&amp;lt;/dueDate&amp;gt;&lt;br /&gt;
   &amp;lt;/order&amp;gt;&lt;br /&gt;
&amp;lt;/orders&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;interface/output/OrdersFixed/orders.csv.txt&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PO10001    43170672 00000120 EA&lt;br /&gt;
PO10002    43170673 00000040 CS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The two output files are named differently because the first output has &amp;lt;code&amp;gt;retainOriginalFilename&amp;lt;/code&amp;gt; set to false and the second has it set to true. See [[Maps#Output file names|Output file names]].&lt;br /&gt;
&lt;br /&gt;
== Seeing what happened ==&lt;br /&gt;
&lt;br /&gt;
Middleware4j keeps a copy of every stage in &amp;lt;code&amp;gt;interface/log&amp;lt;/code&amp;gt;. For the example above the folder holds six files for one input file:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File name contains !! What it is&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;_INPUT_BACKUP_Orders_in1_CSV_&amp;lt;/code&amp;gt; || An untouched copy of the file that arrived.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;_XSLT_INPUT_Orders_in1_CSV_&amp;lt;/code&amp;gt; || The XML made by the input connector.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;_XSLT_INPUT_Orders_out1_XML_&amp;lt;/code&amp;gt; || The XML given to the stylesheet of output &amp;lt;code&amp;gt;out1&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;_XSLT_OUTPUT_Orders_out1_XML_&amp;lt;/code&amp;gt; || The XML that stylesheet produced, which was passed to the XML output connector.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;_XSLT_INPUT_Orders_out2_ASCII_&amp;lt;/code&amp;gt; || The XML given to the stylesheet of output &amp;lt;code&amp;gt;out2&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;_XSLT_OUTPUT_Orders_out2_ASCII_&amp;lt;/code&amp;gt; || The XML that stylesheet produced, which was passed to the ASCII output connector.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Each name starts with the date and time to the millisecond, followed by the map id, the connector id and the connector type, so the files for one map sort together in order.&lt;br /&gt;
&lt;br /&gt;
When an output is not what you expected, open the &amp;lt;code&amp;gt;_XSLT_OUTPUT_&amp;lt;/code&amp;gt; file for that output:&lt;br /&gt;
&lt;br /&gt;
* If the XML in it is wrong, the fault is in the stylesheet.&lt;br /&gt;
* If the XML is right but the final file is wrong, compare it with the layout the output connector expects.&lt;br /&gt;
&lt;br /&gt;
You can also develop a stylesheet outside Middleware4j. Copy an &amp;lt;code&amp;gt;_XSLT_INPUT_&amp;lt;/code&amp;gt; file from the log folder and run your stylesheet against it in an XSLT editor until the result is right. The [[XSLT Extension Functions]] are only available inside Middleware4j, so leave those calls until last.&lt;br /&gt;
&lt;br /&gt;
Files in &amp;lt;code&amp;gt;interface/log&amp;lt;/code&amp;gt; are deleted automatically after the number of days set by &amp;lt;code&amp;gt;logArchiveRetentionDays&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Where to put the stylesheet ==&lt;br /&gt;
&lt;br /&gt;
A stylesheet can be attached to the input connector, to an output connector, or both.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attached to !! Runs !! Use it when&lt;br /&gt;
|-&lt;br /&gt;
| The &amp;#039;&amp;#039;&amp;#039;input&amp;#039;&amp;#039;&amp;#039; connector || Once for each file. Every output receives its result. || All outputs need the same XML, or the map has only one output. Most of the sample maps work this way.&lt;br /&gt;
|-&lt;br /&gt;
| An &amp;#039;&amp;#039;&amp;#039;output&amp;#039;&amp;#039;&amp;#039; connector || Once for that output only. || Different outputs need different XML, as in the example on this page.&lt;br /&gt;
|-&lt;br /&gt;
| Both || The input stylesheet runs first and each output stylesheet then starts from its result. || The input stylesheet tidies the data into a common layout and each output stylesheet makes a small final change.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sending a file to different places depending on its content ==&lt;br /&gt;
&lt;br /&gt;
An output can be given a &amp;lt;code&amp;gt;&amp;amp;lt;condition&amp;amp;gt;&amp;lt;/code&amp;gt;. The output is only written when the condition is true, so one map can route a file to different folders according to a value inside it. The sample map &amp;#039;&amp;#039;&amp;#039;Map13&amp;#039;&amp;#039;&amp;#039; sends a production declaration to one folder when its storage bin is DESPATCH and to another when it is not. See [[Maps#Conditions|Conditions]].&lt;br /&gt;
&lt;br /&gt;
== Using reference data ==&lt;br /&gt;
&lt;br /&gt;
Values that differ from site to site, such as a plant code, are better kept out of the stylesheet. The sample stylesheets read them from small XML files in the &amp;lt;code&amp;gt;xslt&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! File !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;configData.xml&amp;lt;/code&amp;gt; || Single values for the site, such as the host reference, plant and warehouse.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;referenceData.xml&amp;lt;/code&amp;gt; || Translation tables, for example from an ERP plant and storage location to a Commander4j location.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;UOMData.xml&amp;lt;/code&amp;gt; || Unit of measure details for each material.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A stylesheet reads a value with a small function of its own. This one is taken from the sample &amp;lt;code&amp;gt;Map04_CSV_to_XML.xsl&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;HOSTREF&amp;quot;&amp;gt;&amp;lt;xsl:value-of select=&amp;quot;c4j:getConfigItem(&amp;#039;config&amp;#039;,&amp;#039;HostRef&amp;#039;)&amp;quot;/&amp;gt;&amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:function name=&amp;quot;c4j:getConfigItem&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;xsl:param name=&amp;quot;type&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;xsl:param name=&amp;quot;string1&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;xsl:variable name=&amp;quot;item_info&amp;quot; select=&amp;quot;document(&amp;#039;configData.xml&amp;#039;)/lookup&amp;quot;/&amp;gt;&lt;br /&gt;
	&amp;lt;xsl:value-of select=&amp;quot;$item_info/item[@type=$type][@id=$string1]/value&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:function&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The stylesheet must declare the &amp;lt;code&amp;gt;c4j&amp;lt;/code&amp;gt; prefix for this to work: &amp;lt;code&amp;gt;xmlns:c4j=&amp;quot;http://www.commander4j.com&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Checklist when a map does nothing ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Check !! Why&lt;br /&gt;
|-&lt;br /&gt;
| The map and each output have &amp;lt;code&amp;gt;&amp;amp;lt;enabled&amp;amp;gt;true&amp;amp;lt;/enabled&amp;amp;gt;&amp;lt;/code&amp;gt; || A map or output without it is ignored. The value must be the word &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| The file extension matches the mask || With an empty &amp;lt;code&amp;gt;&amp;amp;lt;mask/&amp;amp;gt;&amp;lt;/code&amp;gt; each connector type only picks up its own extensions, for example &amp;lt;code&amp;gt;csv&amp;lt;/code&amp;gt; for a CSV input. See [[Maps#Which files are picked up|Which files are picked up]].&lt;br /&gt;
|-&lt;br /&gt;
| The file is not empty || Empty files are left in the input folder.&lt;br /&gt;
|-&lt;br /&gt;
| Middleware4j was restarted || &amp;lt;code&amp;gt;config.xml&amp;lt;/code&amp;gt; is only read at start up.&lt;br /&gt;
|-&lt;br /&gt;
| The stylesheet output has a single root element || The result is read back as an XML document before it is passed to the output connector.&lt;br /&gt;
|-&lt;br /&gt;
| The stylesheet output matches the layout for the output connector || A CSV output, for example, writes an empty file if the rows have no &amp;lt;code&amp;gt;cols&amp;lt;/code&amp;gt; attribute. See [[Connectors]].&lt;br /&gt;
|-&lt;br /&gt;
| The &amp;lt;code&amp;gt;logs&amp;lt;/code&amp;gt; folder || &amp;lt;code&amp;gt;logs/c4jMiddleware.log&amp;lt;/code&amp;gt; records every step and any error message from the stylesheet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
See also: [[Maps]], [[Connectors]], [[XSLT Extension Functions]], [[Middleware4j Example Configuration]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Middleware4j]]&lt;/div&gt;</summary>
		<author><name>Dgarratt</name></author>
	</entry>
</feed>