So, let's demonstrate using the
Stylus Studio®
XSLT mapper to go
from an
EDIFACT ORDERS "Purchase order message" document in version D03B
to a response X12 831
"Application Control Totals" document in release 003040. The use-case would be we need to
forward the order quantity and transaction amount from a fulfillment system that speaks in a
newer dialect of EDIFACT
to an accounting system that speaks an older variant of X12.

Here are the steps we're going to follow: (some of which are optional)

For the source of our transform, we can either use a sample EDIFACT document or
use a schema representing the EDIFACT D03B ORDERS structure. Since we've got a document,
we're all set. Otherwise, we could follow these steps to
generate an XML Schema for an EDIFACT message.

For our demonstration, we'll assume all files are local in the C:\test
directory. Our instance document will be the one from
edifact-sample.txt
that's been used in other demonstrations.

Click on the Add Source Document button on the top left, and choose the edifact-sample.txt
file, but before pressing Open, check the "Convert to XML using converter" box. Next,
when prompted for the converter type, choose "Electronic Data Interchange (EDI)" and
press OK.

Click on the Set Target Document button on the top right, and
choose the 3040-831.xsd XML schema document.

Next we map the elements that are exactly the same between the left and the right sides. To
do this, we click on the element on the left and drag it to the corresponding element on the
right. You can watch the XSLT code (or XQuery, for the XQuery mapper) being updated in real-time
in the bottom window.

For example, EDIFACT/UNB/UNB04/UNB0402 is
the "0019: date and time of preparation — time" which is in the same format as
X12/ISA/ISA10, and
and EDIFACT/UNB/UNB05 is
the "0020: interchange control reference" which maps to X12/ISA/ISA13 which is the
"I12: interchange control number."

(All of that can be gleaned from the
EDIFACT dictionary available in the1
Stylus Studio® EDIFACT Zone, and/or
the generated schemas which include documentation. X12 documentation can be purchased from
DISA
directly for a nominal fee, or often the subset necessary is included with the application that
produces or consumes the relevant transaction set.)

We proceed in this fashion until all of the fields that have corresponding
entries between EDIFACT and X12 are mapped.

Some of the values in the output are not going to change between runs, such as the
release number and encoding. We need to set those to be literal values. To do this,
right click on the node in the target tree on the right, and choose "Set Text Value"
from the menu. As an example, choose X12/ISA/ISA12 which contains the
release number, and set it to the five-digit sequence "00304". A red
T
will appear over the node so that you know it has a text value.

Some of the mappings require a little more effort. For example, the dates in the
version of EDIFACT we are using are in the YYYYMMDD format, but the X12 release
uses YYMMDD.

So, to connect from EDIFACT/UNB/UNB04/UNB0401
to X12/ISA/ISA09, we'd need to insert
a substring function to eliminate the first two characters.

To do that, right-click on the canvas in the middle and choose XSLT Functions|substring.

Then draw a line from the UNB0401 to the top port on the left side of the function block.
And a line from the port on the right side to the ISA09.
Then double-click on the middle port on the left, and put
in the starting position of 3, and double-click on the bottom port on the left and set the length to 6.

(click to enlarge)

A few more of those, and the mapping is completed, yielding the completed
edifact-to-x12.xsl transform, which you
can just copy and paste into your editor from here.

One final optional step is to make sure what we're generating is in fact complete.
Using the same 003040 X12 831 XML Schema we
used earlier, we can do post-processing validation which will catch any necessary
elements we missed or anything we mismapped.

Open the Scenario Properties and choose the Validation tab.
Make sure "Validate stylesheete result" is checked, and add the 831 schema, so that it
looks like this:

Now whenever you run the transform, the output will automatically be validated for
you.

What's New for Stylus Studio® X16?

Why Pay More for XML Tools?

With Stylus Studio® X16 XML Enterprise Suite, you get the most comprehensive XML tool suite at one incredibly low price. Value: it's just one of many reasons why smart XML developers are choosing Stylus Studio!