Home > XML IDE - XML Editor > XML Editor Key Features > EDI Tools > XML to EDIFACT
Translating XML documents to EDIFACTOnce an XML document is created that contains the proper content to fill an EDIFACT structure, the adapter will do the syntactical translating for you. But how do you get the XML data to look right? Using the same steps as in Converting EDIFACT to XML, we're going to load an EDIFACT document into the editor, change it, and save it back out — and we'll watch the change occur. This will demonstrate an XML document turning back into EDIFACT. Then we'll see how we can do this automatically as part of an XSLT transformation. Here are the steps for this demonstration:
Open the EDIFACT document in the XML editorPerform the following steps:
Change XML EDIFACTLet's change the recipient from DATADIRECT to SAXONICA. Before:
<UNB03> After:
<UNB03> Save XML document in EDIFACT formatDo See changed EDIFACTComparing the two files shows that you just changed an EDIFACT document without an EDIFACT editor, or even seeing the EDIFACT file itself! Use EDIFACT document as output of XSLTWe could automate this, and take the input document, change it with XSLT or XQuery, and save it as a new EDIFACT document with our change. Here are the steps:
<xsl:stylesheet version="1.0">
<xsl:template match="/"> <xsl:apply-templates select="node()"/> </xsl:template> <xsl:template match="UNB0301"> <xsl:element name="{local-name(.)}"> <xsl:text>SAXONICA</xsl:text> </xsl:element> </xsl:template> <xsl:template match="node()"> <xsl:choose> <xsl:when test="local-name(.) = '#text'"> <xsl:value-of select="."/> </xsl:when> <xsl:when test="local-name(.) = '#comment'"/> <xsl:otherwise> <xsl:element name="{local-name(.)}"> <xsl:apply-templates select="node()"/> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> What this does is the same thing we just did, but mechanically. It finds the UNB0301 segment and replaces whatever content text was there with the string SAXONICA. It also filters out any comments (but we could pass them along by replacing the line <xsl:when test="local-name(.) = '#comment'"/>
with the lines <xsl:when test="local-name(.) = '#comment'">
but we don't really need them.)
<xsl:comment> <xsl:value-of select="."/> </xsl:comment> </xsl:when> The EDIFACT can be generated completely from XSLTor XQuery, and schemas can be generated against which to map and validate your EDIFACT XML. The adapters can be used in other contexts as well. They may be built right in to your own applications, using either the data conversion API or as part of your file handling or XSLT/XQuery processing through the deployment adapters.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Try Stylus EDI ToolsSimplify 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! Ask Someone You KnowDoes your company use Stylus Studio? Do your competitors? Engineers from over 100,000 leading companies use Stylus Studio, and now you can ask someone from your own organization about their experiences using Stylus Studio. Stylus Studio® EDIFACT ZoneSimplify your next legacy data integration project with the help of the EDIFACT Zone, the world's largest, free online reference covering all EDIFACT and UN/CEFACT versions. Related XSD Features & Tutorials |