Subject: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:
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.
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.
Subject: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'
Subject: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
}