Monday, August 20, 2007

My first xquery; xml to csv

Got this working. Thought I'd post it. My first xquery. Parses an Xml response file (from a credit card authorisation system), and outputs some of the fields as a csv file. It was written using the BEA XQuery Mapper, which is a pluggin by BEA for eclipse 3.1.

Having an issue running it with Saxon at the moment

declare namespace xf = "";

declare function xf:csv($aPIMessage1 as element(APIMessage))
as xs:string {
concat(for $line in $aPIMessage1/AuthResponse
let $ct := concat($line/ClientTransactionReference, "," , $line/SystemReferenceNumber, ",", $line/ResponseInfo/ResponseCode , ",", $line/ResponseInfo/Result ,",", $line/ResponseInfo/Description , ",", $line/ApprovalInfo/ApprovalCode , ",", $line/ApprovalInfo/DateTime, " ")
return $ct)

declare variable $aPIMessage1 as element(APIMessage) external;


No comments: