Monday, August 20, 2007

Working with saxon

Saxon didn't like the concatenation of the sequence. changing this to fn:string-join worked however.


declare namespace xf = "http://tempuri.org/xqueryTest/XQueryTransformations/csv/";

declare function xf:csv($aPIMessage1 as element(APIMessage))
as xs:string {
fn:string-join(
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;

xf:csv(doc("./resp.xml")/APIMessage)

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 = "http://tempuri.org/xqueryTest/XQueryTransformations/csv/";

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;

xf:csv($aPIMessage1)