XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Roel van der HoevenSubject: EDI to XML
Author: Roel van der Hoeven
Date: 15 May 2009 10:03 AM
We're using XQuery to translate EDI to XML.

Whenever we open an EDI file through XML converter (using a sef file) it gives us an overview of all segments in this message.

Let's say for instance in a group within the EDI message there are a possible of 4 RFF segments. Stylus studio presents them like one RFF "group" with 4 sub composites, something like:

RFF
--RFF01-C506-ACompositeType
----RFF0101-1153ElementType
----RFF0102-1154ElementType
--RFF01-C506-RCompositeType
----RFF0101-1153ElementType
----RFF0102-1154ElementType
--RFF01-C506-UnCompositeType
----RFF0101-1153ElementType
----RFF0102-1154ElementType
--RFF01-C506-6CompositeType
----RFF0101-1153ElementType
----RFF0102-1154ElementType

Let's say the RFF segment are numbered, the qualifier in RFF0101-1153ElementType would be 1, 2, 3 and 4 so the EDI file would read:

RFF+1:number1'
RFF+2:number2'
RFF+3:number3'
RFF+4:number4'

In this case RFF01-C506-ACompositeType (mind the "A" in there) would reference to RFF+1, and RFF01-C506-RCompositeType (again, mind the "R") would be RFF+2, and so on.

This is something I can handle... (phew.....) however for arguments sake let us say these RFF segments are optional, and my EDI file reads:

RFF+1:number1'
RFF+3:number3'

In this case RFF01-C506-ACompositeType still correspondes with RFF+1, however RFF01-C506-RCompositeType is now related to RFF+3 and not like in the top example RFF01-C506-UnCompositeType.

Is there an easy way to handle these situations?

For example I could do a for loop:

for $RFF in $input/EDIFACT/GROUP/COPRAR/GROUP_1/RFF
where $RFF/RFF01-C506-RCompositeType/RFF0101-1153ElementType/text() = 1

But I would have to do this 4 times (note the A, R, Un and 6 before Compositetype > RFF01-C506-RCompositeType), could I use a wildcard of somekind making it like:

for $RFF in $input/EDIFACT/GROUP/COPRAR/GROUP_1/RFF
where $RFF/*/RFF0101-1153ElementType/text() = 1

I hope my problem is clear, if anyone has any difficulties trying to understand this post, please let me know.

Postnext
(Deleted User) Subject: EDI to XML
Author: (Deleted User)
Date: 15 May 2009 12:53 PM
Originally Posted: 15 May 2009 12:45 PM
Our xquery expert suggests this:

for $RFF in $input/EDIFACT/GROUP/COPRAR/GROUP_1/RFF
where $RFF/*[matches(local-name(), "RFF01-C506-.?CompositeType")]/RFF0101-1153ElementType/text() = 1

But to better understand your issue, can you please attach the .sef file and maybe a sample document?

Thanks very much
Clyde Kessel
XML Converters team.

Postnext
Roel van der HoevenSubject: EDI to XML
Author: Roel van der Hoeven
Date: 18 May 2009 02:56 AM
Originally Posted: 18 May 2009 02:50 AM
Here are the sef and EDI files

I understand how this "wildcard" works in the where clause, but I can't seem to get it to work in the output (return).


UnknownECS_COPRAR_M121.sef
SEF file

UnknownCOPRAR_var.edi
EDI file

Postnext
Roel van der HoevenSubject: EDI to XML
Author: Roel van der Hoeven
Date: 18 May 2009 03:03 AM
The return part would be the same right?

for $RFF in $input/EDIFACT/GROUP/COPRAR/GROUP_1/RFF
where $RFF/*[matches(local-name(), "RFF01-C506-.?CompositeType")]/RFF0101-1153ElementType/text() = 'SSX'

return $RFF/*[matches(local-name(), "RFF01-C506-.?CompositeType")]/RFF0102-1154ElementType/text()

Postnext
Roel van der HoevenSubject: EDI to XML
Author: Roel van der Hoeven
Date: 18 May 2009 09:22 AM
Then I also have another problem:

I have 3 other RFF segments:

RFF+CN
RFF+BN
RFF+TF

They can all be present, but only one is relevant. That is in the following order:

If CN is present use CN, otherwise use BN, and if that's not present, use TF. At least one of these segments is available.

Postnext
Tony LavinioSubject: EDI to XML
Author: Tony Lavinio
Date: 22 May 2009 08:34 AM
You could use something like this:

(RFF[RFF01='CN'], RFF[RFF01='BN'], RFF[RFF01='TF'])[1]

That will build a sequence of the 1..3 items, and then
just use the first one it finds.

Posttop
Roel van der HoevenSubject: EDI to XML
Author: Roel van der Hoeven
Date: 08 Jun 2009 09:14 AM
Can you collaborate on this subject? I have 4 NAD segments which read: NAD+CA+value
NAD+CF+value
NAD+MR+value
NAD+MS+value

The last one is not relevant at this point.

If MR is present is needs to give it's value, otherwise CF and the last in this order is CA.

The file I'm receiving reads the above order:
NAD+CA+value NAD-CA:03:20'
NAD+CF+value NAD-CF:04:20'
NAD+MR+value NAD-MR:MR:20'
NAD+MS+value NAD-MS:02:20'

When I do the following:
{let $i := for $x in/EDIFACT/COARRI/GROUP_2/(NAD[NAD01='MR'],NAD[NAD01='CF'],NAD[NAD01='CA'])[1] return $x/NAD02/NAD0201/text()
return $i
}

It gives me:
value NAD-CAvalue NAD-CFvalue NAD-MR

When I use the row indicator [1] on the output:
{let $i := for $x in/EDIFACT/COARRI/GROUP_2/(NAD[NAD01='MR'],NAD[NAD01='CF'],NAD[NAD01='CA']) return $x/NAD02/NAD0201/text()
return $i[1]

It returns: value NAD+CA

It seems to order on occurance in the EDI file, and not the order I give in the function.

Any thoughts on this one?

Quick and dirty way I solved it:

{
let $NAD_MR := for $NAD in /EDIFACT/COARRI/GROUP_2/NAD
where $NAD/NAD01 = 'MR'
return $NAD/NAD02/NAD0201/text()
return
if(string-length($NAD_MR) > 0) then $NAD_MR
else
let $NAD_CF := for $NAD in /EDIFACT/COARRI/GROUP_2/NAD
where $NAD/NAD01 = 'CF'
return $NAD/NAD02/NAD0201/text()
return
if(string-length($NAD_CF) > 0) then $NAD_CF
else
let $NAD_CA := for $NAD in /EDIFACT/COARRI/GROUP_2/NAD
where $NAD/NAD01 = 'CA'
return $NAD/NAD02/NAD0201/text()
return $NAD_CA
}

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.