如何比较并从多源匹配和条件结果中获取结果到目标

how to compare and get result from multiple source matching and conditional result to target

我有两个来源 xmls(更新和编辑)

<?xml version="1.0" encoding="UTF-8"?>
        <CustomerInformation xmlns="http://updateContactDetails.sc.cz.fc.ofss.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://updateContactDetails.sc.cz.fc.ofss.com UpdateContact.xsd ">
          <IntegrationID>099009301</IntegrationID>
          <BrandName>SLOFT</BrandName>      
          <CorrelationId>2312312</CorrelationId>            
          <ProductSystemCustomerDetail>
            <Password>Password</Password>
            <ProductSystemDetails>
              <ProductSystemDetail>
                <ProductSystemID>SYS1</ProductSystemID>
                <ProductSystemCustomerID>1001</ProductSystemCustomerID>
              </ProductSystemDetail>
              <ProductSystemDetail>
                <ProductSystemID>SYS2</ProductSystemID>
                <ProductSystemCustomerID>1002</ProductSystemCustomerID>
              </ProductSystemDetail>
              <ProductSystemDetail>
                <ProductSystemID>SYS3</ProductSystemID>
                <ProductSystemCustomerID>1003</ProductSystemCustomerID>
              </ProductSystemDetail>
    <ProductSystemDetail>
                <ProductSystemID>SYS3</ProductSystemID>
                <ProductSystemCustomerID>1112</ProductSystemCustomerID>
              </ProductSystemDetail>
            </ProductSystemDetails>
          </ProductSystemCustomerDetail>
        </CustomerInformation>

我从对象生成的第二个 xml 是:

<ns:getPerson_Output xmlns:ns="http://apps/customer">     
         <ListOfSwiPersonIO>
            <Contact operation="Query">               
               <ModId>3</ModId>
               <Status>A</Status>
               <PartyState>19</PartyState>
               <Type>IND</Type>               
               <Organization>48</Organization>
               <OrganizationId>1-MCKOL</OrganizationId>
               <MigratedFlag>N</MigratedFlag>
               <LastName>SCEPTOR</LastName>
               <FirstName>MARK</FirstName>               
               <MM>87</MM> 
               <ListOfCIFContactReference>
                  <CIFContactReference>
                     <SystemNumber>SYS1</SystemNumber>
                     <SystemName>SYS1</SystemName>
                     <ExternalId>1001</ExternalId>
                  </CIFContactReference>
                  <CIFContactReference>
                     <SystemNumber>SYS2</SystemNumber>
                     <SystemName>SYS2</SystemName>
                     <ExternalId>1008</ExternalId>
                  </CIFContactReference>
                  <CIFContactReference>
                     <SystemNumber>SYS4</SystemNumber>
                     <SystemName>SYS4</SystemName>
                     <ExternalId>1009</ExternalId>
                  </CIFContactReference>
               </ListOfCIFContactReference>
            </Contact>
         </ListOfSwiPersonIO>
      </ns:getPerson_Output>

我的输出应该是

    <Update_OCHCrossReferencePerson_Req>
<part  name="UpdatePersonCrossReference_Input">
<UpdatePersonCrossReference_Input>
<xsdLocal3:ListOfSwiPersonPublishIO>
<xsdLocal3:Contact>
<xsdLocal3:IntegrationId>099009301</xsdLocal3:IntegrationId>
<xsdLocal3:ListOfCIFContactReference>
<xsdLocal3:CIFContactReference>
<xsdLocal3:SystemNumber>SYS2</xsdLocal3:SystemNumber>
<xsdLocal3:SystemName>SYS2</xsdLocal3:SystemName>
<xsdLocal3:ExternalId>1002</xsdLocal3:ExternalId>
</xsdLocal3:CIFContactReference><xsdLocal3:CIFContactReference>
<xsdLocal3:SystemNumber>SYS1</xsdLocal3:SystemNumber>
<xsdLocal3:SystemName>SYS1</xsdLocal3:SystemName>
<xsdLocal3:ExternalId>1001</xsdLocal3:ExternalId>
</xsdLocal3:CIFContactReference>
<xsdLocal3:CIFContactReference>
<xsdLocal3:SystemNumber>SYS3</xsdLocal3:SystemNumber>
<xsdLocal3:SystemName>SYS3</xsdLocal3:SystemName>
<xsdLocal3:ExternalId>1003</xsdLocal3:ExternalId>
</xsdLocal3:CIFContactReference>
<xsdLocal3:CIFContactReference>
<xsdLocal3:SystemNumber>SYS3</xsdLocal3:SystemNumber>
<xsdLocal3:SystemName>SYS3</xsdLocal3:SystemName>
<xsdLocal3:ExternalId>1112</xsdLocal3:ExternalId>
</xsdLocal3:CIFContactReference>
</xsdLocal3:ListOfCIFContactReference>
</xsdLocal3:Contact>
</xsdLocal3:ListOfSwiPersonPublishIO>
</UpdatePersonCrossReference_Input>
</part>
</Update_OCHCrossReferencePerson_Req>



Explanation: if system number is same and id has changed. I need to update id. if there is any extra system added in first xml I need to add it in target xml. Problem is when i try to segregate it adds excluded system numbers as well.

My xslt is :




  <?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper
  <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
  <mapSources>
    <source type="WSDL">
      <schema location="../UpdateDetailsV1.wsdl"/>
      <rootElement name="CustomerInformation" namespace="http://updateContactDetails.sc.cz.fc.ofss.com"/>
    </source>
    <source type="WSDL">
      <schema location="../OCHPersonService.wsdl"/>
      <rootElement name="getPerson_Output" namespace="http://xmlns.oracle.com/apps/mdm/customer"/>
      <param name="getPersonOutputVariable.getPerson_Output" />
    </source>
  </mapSources>
  <mapTargets>
    <target type="WSDL">
      <schema location="../OCHPersonCrossReferenceService.wsdl"/>
      <rootElement name="updatePersonCrossReference_Input" namespace="http://xmlns.oracle.com/apps/mdm/customer"/>
    </target>
  </mapTargets>
  <!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.7.0(build 140401.1420.0097) AT [THU MAR 12 09:59:26 EST 2015]. -->
?>
<xsl:stylesheet version="1.0"
                xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
                xmlns:xsdLocal1="http://www.siebel.com/xml/SwiPersonIO"
                xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:xsdLocal3="http://www.siebel.com/xml/SwiPersonPublishIO"
                xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
                xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
                xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
                xmlns:ora="http://schemas.oracle.com/xpath/extension"
                xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
                xmlns:xsdLocal2="http://www.siebel.com/xml/UCMMergeRequestRs"
                xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
                xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
                xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
                xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
                xmlns:med="http://schemas.oracle.com/mediator/xpath"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:tns="http://updateContactDetails.sc.cz.fc.ofss.com"
                xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
                xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
                xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:ns0="http://xmlns.oracle.com/apps/mdm/customer"
                xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
                exclude-result-prefixes="xsi xsl xsdLocal1 xsdLocal3 soapenc soap mime xsdLocal2 tns xsd ns0 xp20 bpws bpel bpm ora socket mhdr oraext dvm hwf med ids xdk xref ldap">
  <xsl:param name="getPersonOutputVariable.getPerson_Output"/>
  <xsl:template match="/">
    <ns0:updatePersonCrossReference_Input>
      <xsdLocal3:ListOfSwiPersonPublishIO>
        <xsdLocal3:Contact>
          <xsdLocal3:IntegrationId>
            <xsl:value-of select="/tns:CustomerInformation/tns:IntegrationID"/>
          </xsdLocal3:IntegrationId>
          <xsdLocal3:ListOfCIFContactReference>
             <xsl:for-each select="/tns:CustomerInformation/tns:ProductSystemCustomerDetail/tns:ProductSystemDetails/tns:ProductSystemDetail">
             <xsl:variable name="newSystemId" select="tns:ProductSystemID" />
             <xsl:variable name="newExternalId" value="tns:ProductSystemCustomerID"/>
                <xsl:if test="number($getPersonOutputVariable.getPerson_Output/ns0:getPerson_Output/xsdLocal1:ListOfSwiPersonIO/xsdLocal1:Contact/xsdLocal1:ListOfCIFContactReference/xsdLocal1:CIFContactReference[xsdLocal1:SystemNumber = $newSystemId]/xsdLocal1:ExternalId/text()) != number($newExternalId)">
                <xsdLocal3:CIFContactReference>
                  <xsdLocal3:SystemName>
                        <xsl:value-of select="$newSystemId"/>
                  </xsdLocal3:SystemName>
                  <xsdLocal3:SystemNumber>
                    <xsl:value-of select="$getPersonOutputVariable.getPerson_Output/ns0:getPerson_Output/xsdLocal1:ListOfSwiPersonIO/xsdLocal1:Contact/xsdLocal1:ListOfCIFContactReference/xsdLocal1:CIFContactReference[xsdLocal1:SystemNumber = $newSystemId]/xsdLocal1:ExternalId"/>
                  </xsdLocal3:SystemNumber>
                  <xsdLocal3:ExternalId>
                    <xsl:value-of select="$getPersonOutputVariable.getPerson_Output/ns0:getPerson_Output/xsdLocal1:ListOfSwiPersonIO/xsdLocal1:Contact/xsdLocal1:ListOfCIFContactReference/xsdLocal1:CIFContactReference[xsdLocal1:ExternalId != $newExternalId]/xsdLocal1:ExternalId"/>
                  </xsdLocal3:ExternalId>
                </xsdLocal3:CIFContactReference>
                </xsl:if>
              </xsl:for-each>            
          </xsdLocal3:ListOfCIFContactReference>
        </xsdLocal3:Contact>
      </xsdLocal3:ListOfSwiPersonPublishIO>
    </ns0:updatePersonCrossReference_Input>
  </xsl:template>
</xsl:stylesheet>


**kbhkasbndkaskda

PS:我有两个源和一个目标 xsd 需要映射这些更改。我使用的是 xslt 1.0,所有 xsd 都已嵌入。即我不能使用文件 xml 来引用它。

我根本无法理解您的 XSLT。坚持这个解释:

Explanation: if system number is same and id has changed. I need to update id. if there is any extra system added in first xml I need to add it in target xml.

我相信你想将转换应用到你的第二个 XML:

XML

<ListReference>
  <Reference>
    <SystemNumber>SYS1</SystemNumber>
    <ExternalId>9000</ExternalId>
  </Reference>
  <Reference>
    <SystemNumber>SYS4</SystemNumber>
    <ExternalId>2534401</ExternalId>
  </Reference>
</ListReference>

并将第一个 XML 引用为样式表中的外部文档。我已将此更正为:

File2.xml

<Info>
  <CustomerDetail>
    <Password>Password</Password>
    <SystemDetails>
      <SystemDetail>
        <SystemID>SYS1</SystemID>
        <SystemCustomerID>1001</SystemCustomerID>
      </SystemDetail>
      <SystemDetail>
        <SystemID>SYS2</SystemID>
        <SystemCustomerID>1001</SystemCustomerID>
      </SystemDetail>
      <SystemDetail>
        <SystemID>SYS3</SystemID>
        <SystemCustomerID>1001</SystemCustomerID>
      </SystemDetail>
    </SystemDetails>
  </CustomerDetail>
</Info>

有了这个,下面的样式表:

XSLT 1.0

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:param name="file2" select="document('File2.xml')" />

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="/ListReference">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
        <xsl:variable name="system-numbers" select="Reference/SystemNumber" />
        <xsl:apply-templates select="$file2/Info/CustomerDetail/SystemDetails/SystemDetail[not(SystemID=$system-numbers)]"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="ExternalId">
    <xsl:copy>
        <xsl:variable name="other-system" select="$file2/Info/CustomerDetail/SystemDetails/SystemDetail[SystemID=current()/../SystemNumber]" />
        <xsl:choose>
            <xsl:when test="$other-system">
                <xsl:value-of select="$other-system/SystemCustomerID"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:copy>
</xsl:template>

<xsl:template match="SystemDetail">
    <Reference>
        <SystemNumber>
            <xsl:value-of select="SystemID"/>
        </SystemNumber>              
        <ExternalId>
            <xsl:value-of select="SystemCustomerID"/>
        </ExternalId>
    </Reference>
</xsl:template>

</xsl:stylesheet>

将return以下结果

<?xml version="1.0" encoding="UTF-8"?>
<ListReference>
   <Reference>
      <SystemNumber>SYS1</SystemNumber>
      <ExternalId>1001</ExternalId>
   </Reference>
   <Reference>
      <SystemNumber>SYS4</SystemNumber>
      <ExternalId>2534401</ExternalId>
   </Reference>
   <Reference>
      <SystemNumber>SYS2</SystemNumber>
      <ExternalId>1001</ExternalId>
   </Reference>
   <Reference>
      <SystemNumber>SYS3</SystemNumber>
      <ExternalId>1001</ExternalId>
   </Reference>
</ListReference>