XSLT根据Key值XSLT1.0对xml元素进行分组

时间:2015-01-09 13:46:12

标签: xslt biztalk

我将在BizTalk

中收到如下的CRM Response XML
<ns0:RetrieveMultipleResponse xmlns:ns0="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:ns3="http://schemas.microsoft.com/xrm/2011/Metadata" xmlns:ns5="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" xmlns:ns4="http://schemas.microsoft.com/xrm/2011/Contracts">
<ns0:RetrieveMultipleResult>
    <ns4:Entities>
      <ns4:Entity>
        <b:Attributes xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
            <b:KeyValuePairOfstringanyType>
            <c:key>ccx_datevaccineinfostatementpresented</c:key>
            <c:value i:type="d:dateTime" xmlns:d="http://www.w3.org/2001/XMLSchema">2012-08-14T04:00:00Z</c:value>
          </b:KeyValuePairOfstringanyType>
          <b:KeyValuePairOfstringanyType>
            <c:key>ccx_administeredamount</c:key>
            <c:value i:type="d:decimal" xmlns:d="http://www.w3.org/2001/XMLSchema">0.75000000</c:value>
          </b:KeyValuePairOfstringanyType>
          <b:KeyValuePairOfstringanyType>
            <c:key>ccx_immunizationid</c:key>
            <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">826c2b0e-a349-e411-866c-00155d1e1f77</c:value>
          </b:KeyValuePairOfstringanyType>
     </b:Attributes>
  </ns4:Entity>
   <ns4:Entity>
        <b:Attributes xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
            <b:KeyValuePairOfstringanyType>
            <c:key>ccx_datevaccineinfostatementpresented</c:key>
            <c:value i:type="d:dateTime" xmlns:d="http://www.w3.org/2001/XMLSchema">2012-08-14T04:00:00Z</c:value>
          </b:KeyValuePairOfstringanyType>
          <b:KeyValuePairOfstringanyType>
            <c:key>ccx_administeredamount</c:key>
            <c:value i:type="d:decimal" xmlns:d="http://www.w3.org/2001/XMLSchema">0.25000</c:value>
          </b:KeyValuePairOfstringanyType>
          <b:KeyValuePairOfstringanyType>
            <c:key>ccx_immunizationid</c:key>
            <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">766c2b0e-a349-e411-866c-00155d1e1f77</c:value>
          </b:KeyValuePairOfstringanyType>
     </b:Attributes>
  </ns4:Entity>
<ns4:Entity>
        <b:Attributes xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
            <b:KeyValuePairOfstringanyType>
            <c:key>ccx_datevaccineinfostatementpresented</c:key>
            <c:value i:type="d:dateTime" xmlns:d="http://www.w3.org/2001/XMLSchema">2012-08-14T04:00:00Z</c:value>
          </b:KeyValuePairOfstringanyType>
          <b:KeyValuePairOfstringanyType>
            <c:key>ccx_administeredamount</c:key>
            <c:value i:type="d:decimal" xmlns:d="http://www.w3.org/2001/XMLSchema">0.7500000000</c:value>
          </b:KeyValuePairOfstringanyType>
          <b:KeyValuePairOfstringanyType>
            <c:key>ccx_immunizationid</c:key>
            <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">826c2b0e-a349-e411-866c-00155d1e1f77</c:value>
          </b:KeyValuePairOfstringanyType>
     </b:Attributes>
  </ns4:Entity>
</Entities>

我必须根据ccx_immunizationid值计算不同的实体数量&amp;如果两个实体具有相同的免疫ID,我也必须对这些字段进行分组。如果xml文件(没有名称空间)和字段是<ccx_immunizationid>2323</ccx_imunizationid>,我可以使用类似下面的内容,

<xsl:template match="//Entity/Attributes[not(./ccx_immunizationid= preceding::ccx_immunizationid)]">

但是在这里,我必须查找键'ccx_immunizationid'及其值。

我在BizTalk地图中使用自定义xslt。

0 个答案:

没有答案