Archive for October, 2008

Using Inline XSLT to Create Target Nodes

Posted in EDI on October 31, 2008 by mdbeckner

Creating nodes using Inline XSLT often eliminates much of the complexity around mapping.  To demonstrate how to use XSLT, this post will illustrate an XSLT script that created three N1 target records using two “dynamic” input records and one “static” record.

The input has two out of the three records, the third record is hard coded into the XSLT.

The Map looks as follows:

The Map

The Map

As can be seen, the source XML has a node called “TradingPartners” that contains the two dynamic records.  The XSLT script will loop through all of the incoming TradingPartner nodes and create N1 elements based on those.  Once all of the TradingPartner nodes have been looped through, the XSLT will create one final element based on static values.  The XSLT script is shown here:
<xsl:for-each select=”//*[local-name()='TradingPartner']“>
<xsl:element name=”ns0:N1″>
<xsl:element name=”N101″><xsl:value-of select=”*[local-name()='IDCode']“/></xsl:element>
<xsl:element name=”N102″><xsl:value-of select=”*[local-name()='TPKnownAs']“/></xsl:element>
<xsl:element name=”N103″>9</xsl:element>
<xsl:element name=”N104″><xsl:value-of select=”*[local-name()='TPDUNS']“/></xsl:element>
</xsl:element>
</xsl:for-each>
<xsl:element name=”ns0:N1″>
<xsl:element name=”N101″>SF</xsl:element>
<xsl:element name=”N102″>STATIC TRADING PARTNER NAME, INC.</xsl:element>
<xsl:element name=”N103″>9</xsl:element>
<xsl:element name=”N104″>012345697654</xsl:element>
</xsl:element>

* Note that the value-of XSL is looking for “local-name()”.  This enables source documents with namespace prefixes (such as ns0) in them to be mapped.  In this case, the source is <ns0:TradingPartner>. 

Mapping Hierarchical (Structured) XML to Flat XML

Posted in EDI on October 31, 2008 by mdbeckner
To illustrate how to map a hierarchical EDI structure to a target flat structure, I’ll work with the DTM field in an 867.  Assume the following rules:
1. If the DTM01 node = 003, map DTM02 to one node in target schema.
2. If the DTM01 node = 004, map DTM02 to a different node in target schema.
By default, I know that I need to place two “Equals” functoids and two “Value Mapping” functoids to get the values across, as shown here:
Incorrect Mapping (checks only the first occurance of DTM)

Incorrect Mapping (checks only the first occurance of DTM)

With the incorrect output (shown here) showing only one of the targeted nodes.  This is because the map is not looping through all of the source DTM nodes.
Output of Incorrect Mapping

Output of Incorrect Mapping

Knowing that there always two or more DTM nodes in the source, the map will need to be forced to loop through all occurances.  This can be done by adding a “Loop” functoid, with the input being the root DTM node, and the output being both of the desired output nodes.  This map looks as follows:
Correct Mapping (with Loop Functoid)

Correct Mapping (with Loop Functoid)

This will cause the map to loop through all occurances of the source.  Only those occurances which match the “Equals” logic will be mapped across.  The correct output is shown here:
Result

Result