Convert EDIFACT to X12 or vice-versa
Now that we have the tools to transform XML with XSLT or XQuery, convert to XML, and convert from XML, we should be able to directly build maps between EDIFACT/X12 and XML or XML and EDIFACT/X12 or now even EDI and EDI.
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)
After the step-by-step EDI to EDI tutorial here, we'll show the completed XSLT file which you can download and manipulate with Stylus Studio® yourself.
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
To generate the X12 schema as a target, we use
When the XML Schema editor opens, save the document as
Start a new XSLT map by choosing
Click on the
Click on the
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.
(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
Some of the mappings require a little more effort. For example, the dates in the
version of EDIFACT we are using are in the
So, to connect from
To do that, right-click on the canvas in the middle and choose
Then draw a line from the
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.
Okay, press the green triangle, and look at your output.
Note that the preview window itself shows the XML equivalent, you must look at the X12 EDI output by opening it in a text editor, or one of the other editors within Stylus Studio® to look at it.
Below is how the X12 EDI output would look after running our transform.
One final optional step is to make sure what we're generating is in fact complete.
Using the same
Now whenever you run the transform, the output will automatically be validated for you.
Just for fun, let's see what it would take to run this same transform from the command line. All of the following would be typed just on one line:
Congratulations! You now have all of the tools you need to map from EDIFACT to X12, or X12 to EDIFACT, or anything to or from XML.
For further reading:
PURCHASE STYLUS STUDIO ONLINE TODAY!!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Try Stylus EDI Tools
Simplify working with Electronic Data Interchange (EDI) with Stylus Studio®'s award-winning EDI Tools — Download a free trial of our today!
What's New for Stylus Studio® X16?
New XQuery & Web Services Tools, Support for MySQL, PostgreSQL, HL7 EDI, Microsoft .NET Code Generation and much more!