I used a tool to map this xquery but need to understand what the tool did behind the scenes to avoid myself being a slave to the tool
(:: pragma bea:global-element-parameter parameter="$retrieveCustomerByCriteriaResponse1" element="ns0:RetrieveCustomerByCriteriaResponse" location="../wsdl/CustomerService.wsdl" ::)
(:: pragma bea:global-element-return element="ns3:FindCustomerResponse" location="../wsdl/CustomerManagement.wsdl" ::)
declare namespace ns2 = "http://www.somecorp.com/customer";
declare namespace ns1 = "http://www.somecorp.com/creditcard";
declare namespace ns3 = "http://www.somecorp.org/CustomerManagement";
declare namespace ns0 = "http://www.crm.org/CustomerService/";
declare namespace xf = "http://tempuri.org/basic-osb-service/transformation/TransformFindCustomerResponse/";
declare function xf:TransformFindCustomerResponse(**$retrieveCustomerByCriteriaResponse1 as element(ns0:RetrieveCustomerByCriteriaResponse**))
as element(ns3:FindCustomerResponse) {
<ns3:FindCustomerResponse>
<Customer>
<ns2:ID>{ xs:long($retrieveCustomerByCriteriaResponse1/customers/id) }</ns2:ID>
<ns2:FirstName>{ data($retrieveCustomerByCriteriaResponse1/customers/firstname) }</ns2:FirstName>
<ns2:LastName>{ data($retrieveCustomerByCriteriaResponse1/customers/lastname) }</ns2:LastName>
<ns2:EmailAddress>{ data($retrieveCustomerByCriteriaResponse1/customers/emailAddress) }</ns2:EmailAddress>
<ns2:Addresses>
{
let $address := $retrieveCustomerByCriteriaResponse1/customers/address
return
<ns2:Address>
<ns2:Street>{ data($address/street) }</ns2:Street>
<ns2:PostalCode>{ data($address/zipcode) }</ns2:PostalCode>
<ns2:City>{ data($address/city) }</ns2:City>
</ns2:Address>
}
</ns2:Addresses>
<ns2:Rating>{ data($retrieveCustomerByCriteriaResponse1/customers/rating) }</ns2:Rating>
<ns2:Gender>{ data($retrieveCustomerByCriteriaResponse1/customers/gender) }</ns2:Gender>
</Customer>
</ns3:FindCustomerResponse>
};
declare variable $retrieveCustomerByCriteriaResponse1 as element(ns0:RetrieveCustomerByCriteriaResponse) external;
xf:TransformFindCustomerResponse($retrieveCustomerByCriteriaResponse1)
Can someone please explain what this code does?
What is the input parameter to this function ?
The input of this function is an element(), which is basically a XML snippet. Based on the values used within the function it should probably have a structure like this:
Please note, that XML is semi-structured, so there could be information missing from the input snippet (e.g. no email address). of course it could also contain many more information which is simply not used here.
What the script actually does is some simple XPath expression. For example
traverses first to the customer child and then to the id child. The xs:long is a type casting to a long value. What you will get back is something like this (based on the above input):
What I don’t know (and I would actually be very interested to know…) ist what these two asterisk ** in the function declaration mean. I have never seen such a syntax before. Normally, you use the asterisk just for a wildcard for the namespace or as quantifier.