Translating XML documents to X12
The following is a demonstration of in-place editing of X12 content as well as programmatic changing of content, all to demonstrate the bidirectional nature of the EDI converter for X12.
Using the same steps as in Converting X12 to XML, we're going to edit an X12 document with the XML and then save it back out. We will then compare the before-and-after shots to see the change in the EDI file itself. This will demonstrate an XML document turning back into X12.
Then we'll see how this can be automated using XSLT.
Here are the steps for this demonstration:
Perform the following steps:
Since business has been so good, we're going to double our order quantities. (By the way, the 41 value in "Number of batches" means that the quantity is a count of batches, not that there are 41 batches. "41" is the X12 quantity code for "number of batches" — got it?)
Using a 'diff' program to do a side-by-side comparison of the original file with the changed file shows that we were able to alter the X12 file without an X12-specific editor, or even opening the raw X12 file itself!
Let's take a moment and automate what we did — using the input document with a few adjustments to make an output X12 document. Either XSLT or XQuery will do, and we'll just arbitrarily choose the former for our demonstration. Again, what we are going to accomplish is to take an existing X12 document, and save it as a new X12 document with a few modifications.
What this does is the same thing we just did, but mechanically. It finds the
You may have noticed two processing instruction lines being emitted. By default, the characters for segment terminator and element separator are different in the converter than they were in the input file. We can override them by setting them in the output stream, which we did to make our 'diff' easier to read.
In case you are curious, here are the PI directives that can be given, along with their default values:
These also apply to the XML to EDIFACT converter.
The converters are not limited to use within Stylus Studio®. They may be integrated into your own applications directly, using the data conversion API, or included as part of your file handling or XSLT/XQuery processing through the XML Converters.
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!
Learn XQuery in 10 Minutes!
Say goodbye to 10-minute abs, and say Hello to "Learn XQuery in Ten Minutes!", the world's fastest and easiest XQuery primer, now available for free!