【发布时间】:2011-03-03 19:17:40
【问题描述】:
输入是一个 mutliRef 编码的 SOAP 消息/文档。你如何使用 XSLT 扁平化 multiRefs。 Multiref节点可以被引用使用 多次,并且它们自己递归地引用其他 multiRef 节点。
结构中唯一可以安全引用的部分是 multiRef 元素和@id 和@href 属性。其他元素或 命名空间可能会改变。
示例输入消息是:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getAccountDTOResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://www.example.com/pw/services/PWServices">
<getAccountDTOReturn href="#id0" />
</ns1:getAccountDTOResponse>
<multiRef id="id0" soapenc:root="0"
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="ns2:Account"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns2="urn:PWServices">
<ID href="#id1" />
<accountNumber xsi:type="soapenc:string"></accountNumber>
<accountType xsi:type="soapenc:string"></accountType>
<clientData xsi:type="soapenc:Array" xsi:nil="true" />
<name xsi:type="soapenc:string"></name>
<parentRef xsi:type="soapenc:string"></parentRef>
</multiRef>
<multiRef id="id1" soapenc:root="0"
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="xsd:long"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
0</multiRef>
</soapenv:Body>
</soapenv:Envelope>
预期输出是:
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getAccountDTOResponse xmlns:ns1="http://www.example.com/pw/services/PWServices"
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<getAccountDTOReturn xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns2="urn:PWServices"
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="ns2:Account">
<ns1:ID soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="xsd:long">0</ns1:ID>
<ns1:accountNumber xsi:type="soapenc:string" />
<ns1:accountType xsi:type="soapenc:string" />
<ns1:clientData xsi:type="soapenc:Array" xsi:nil="true" />
<ns1:name xsi:type="soapenc:string" />
<ns1:parentRef xsi:type="soapenc:string" />
</getAccountDTOReturn>
</ns1:getAccountDTOResponse>
</soapenv:Body>
</soapenv:Envelope>
更新: 在上面的例子中,从逻辑上讲,应该发生的事情是:
在第一次通过时,getAccountDTOResponse 包含@href="#id0",因此该元素将替换为所有具有@id="id0" 的子 multiRef 元素,但除外。
在第二遍中,@href="#id1" 应该被发现,并且 ID 元素应该被替换为 @id="id1" 元素的内容。
输出中不应存在 multiRef 元素。如果涉及到整个 multiRef 混乱,则输出中不应存在 @id 或 @href 属性。
【问题讨论】:
-
目前还不是很清楚到底应该放入什么。能否请您将此添加到您的问题中?
-
@Dimitre 我在问题的底部添加了一些说明。