我使用了一个工具来映射这个xquery,但需要了解该工具在幕后做了什么,以避免自己成为该工具的奴隶
(:: 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)
有人可以解释这段代码的作用吗? 该函数的输入参数是什么?
答案 0 :(得分:0)
此函数的输入是一个元素(),它基本上是一个XML片段。根据函数中使用的值,它应该具有如下结构:
<ns0:RetrieveCustomerByCriteriaResponse>
<ns0:customers>
<ns0:id>1234</ns0:id>
<ns0:firstname>John</ns0:firstname>
<ns0:lastname>Smith</ns0:lastname>
<ns0:emailAddress>you@gmail.com</ns0:emailAddress>
<ns0:address>
<ns0:street>Main Street</ns0:street>
<ns0:zipcode>12345</ns0:zipcode>
<ns0:city>New York</ns0:city>
</ns0:address>
<ns0:rating>5</ns0:rating>
<ns0:gender>male</ns0:gender>
</ns0:customer>
</ns0:RetrieveCustomerByCriteriaResponse>
请注意,XML是半结构化的,因此输入代码段中可能缺少信息(例如,没有电子邮件地址)。当然它还可能包含更多信息,这些信息在这里根本就不使用。 脚本实际上做的是一些简单的XPath表达式。例如
xs:long($retrieveCustomerByCriteriaResponse1/customers/id) }
首先遍历客户孩子,然后遍历id孩子。 xs:long是一个类型转换为long值。你会得到什么是这样的(基于上面的输入):
<ns3:FindCustomerResponse>
<Customers>
<ns2:ID>1234</ns2:ID>
<ns2:FirstName>John</ns2:FirstName>
<ns2:LastName>Smith</ns2:LastName>
<ns2:EmailAddress>you@gmail.com</ns2:EmailAddress>
<ns2:Addresses>
<ns2:Address>
<ns2:Street>Main Street</ns2:Street>
<ns2:PostalCode>12345</ns2:PostalCode>
<ns2:City>New York</ns2:City>
</ns2:Address>
</ns2:Addresses>
<ns2:Rating>5</ns2:Rating>
<ns2:Gender>male</ns2:Gender>
</Customer>
</ns3:FindCustomerResponse>
我不知道(我实际上非常有兴趣知道......)这两个函数声明中的星号**是什么意思。我以前从未见过这样的语法。通常,您只使用星号作为命名空间的通配符或量词。