The EDIFACT formatter project is available on the accompanying CD-ROM. Copy the project directory from the CD-ROM to your hard disk, go to the command line, and change to the root of the project. You can run the EDIFACT formatter with the xml2edi command (see Figure 5.8). The parameters are the XML file, XSL style sheet, and output file. Figure 5.8. Running with con as the output file prints the result on the console.
Warning This project uses Xalan. You need Xalan and a SAX 1.0 parser to run it. The project on the enclosed CD-ROM uses Xalan and Xerces. Both are available on the CD -ROM , or you can download the latest version from http://xml.apache.org. If you switch to another XSL processor, you will need to rewrite XML2Edifact to accommodate your processor. Warning The compiler might issue deprecation warnings if you recompile the project . At the time of this writing, Xalan uses SAX 1.0 event handlers only, but if your parser is SAX 2.0 compliant, it will warn you during recompilation. XSLT BenefitsOne of the major advantages of using XSLT with a formatter is that modifying the input or output format is easy. Suppose you decide to include the product description in the EDIFACT order. You need to include only the following rule between the PIA and QTY segments. You don't need to modify Java code or recompile: <Segment tag="IMD"> <Simple>F</Simple> <Simple>81</Simple> <Composite> <Simple/> <Simple/> <Simple/> <Simple><xsl:value-of select="Description"/></Simple> </Composite> </Segment> In fact, the converter we have built is not limited to variations of purchase orders. It will work equally well with invoices, reinsurance claims, and Social Security declarations. All it takes is a different style sheet. Tip In my experience, XSL style sheets are less frightening than Java code for nonprogrammers. So, I can use the style sheet and discuss it with customers who would not understand my Java code. This alone is a major argument for using style sheets. |