2017-04-17 53 views
0

我有下面的XML:覆蓋信息的另一XSL轉換

<? xml version="1.0" encoding="UTF-8"?> 
<REQUEST_GROUP MISMOVersionID = "2.3.1" > 
<REQUESTING_PARTY> 
< PREFERRED_RESPONSE _VersionIdentifier="2.3.1" _Format="XML"/> 
</REQUESTING_PARTY> 
<SUBMITTING_PARTY _Name = "NETOX" /> 
< REQUEST LoginAccountPassword="00JfDA.S0rxs6" LoginAccountIdentifier="XXXXX" InternalAccountIdentifier="XXXXX" RequestDatetime="2017-04-17T07:51:23"> 
<REQUEST_DATA> 
    <CREDIT_REQUEST MISMOVersionID = "2.3.1" RequestingPartyRequestedByName="1009" LenderCaseIdentifier="5010904"> 
    <CREDIT_REQUEST_DATA CreditRequestDateTime = "2017-04-17T07:51:23" CreditRequestType="Joint" CreditRepositoriesSelectedCount="0" CreditReportType="Merge" BorrowerID="BNUM2 BNUM1" CreditRequestID="CRQ1" CreditReportRequestActionType="Submit"> 
     <CREDIT_REPOSITORY_INCLUDED _TransUnionIndicator = "Y" _ExperianIndicator="Y" _EquifaxIndicator="Y"/> 
    </CREDIT_REQUEST_DATA> 
    <LOAN_APPLICATION> 
     <BORROWER BorrowerID = "BNUM2" JointAssetLiabilityReportingType="NotJointly" JointAssetBorrowerID="BNUM1" _PrintPositionType="Borrower" SchoolingYears="18" _SSN="500222000" _LastName="Homeowner" _HomeTelephoneNumber="9185454545" _FirstName="Mary" _BirthDate="19850202" _AgeAtApplicationYears="32"> 
     <_RESIDENCE _PostalCode = "74133" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="3214 E 30th Pl" BorrowerResidencyType="Current"/> 
     </BORROWER> 
     <BORROWER BorrowerID = "BNUM1" JointAssetLiabilityReportingType="NotJointly" JointAssetBorrowerID="BNUM2" _PrintPositionType="CoBorrower" SchoolingYears="21" _SSN="999405000" _LastName="Homeowner" _HomeTelephoneNumber="9185874547" _FirstName="John" _BirthDate="19780202" _AgeAtApplicationYears="39" MaritalStatusType="Unmarried"> 
     <_RESIDENCE _PostalCode = "74136" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="6600 S Yale Avenue" BorrowerResidencyType="Current"/> 
     </BORROWER> 
    </LOAN_APPLICATION> 
    </CREDIT_REQUEST> 
</REQUEST_DATA> 
</REQUEST> 

<MAILING_ADDRESS _PostalCode = "74137" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="1234 Fake St" BorrowerResidencyType="Current" _Bnum="2"/> 
<MAILING_ADDRESS _PostalCode = "74133" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="7777 S Memorial Drive" BorrowerResidencyType="Current" _Bnum="1"/> 

</REQUEST_GROUP> 

我需要將覆蓋與用於每個借款的MAILING_ADDRESS信息_RESIDENCE節點的信息。在BORROWER節點中有BorrowerID,它對應於Mailing_Address中的_Bnum。 _RESIDENCE仍然應該是節點;只有信息應該改變。我嘗試過的所有東西都以具有相同地址信息的借款人結束。

+0

「*在BORROWER節點中有BorrowerID,它對應於Mailing_Address中的_Bnum。*」我沒有看到它的確如此。 –

回答

0

好吧,給這個XML(不得不清理格式化一下)。

<REQUEST_GROUP MISMOVersionID = "2.3.1" > 
<REQUESTING_PARTY > 
<PREFERRED_RESPONSE _VersionIdentifier="2.3.1" _Format="XML"/> 
</REQUESTING_PARTY> 
<SUBMITTING_PARTY _Name = "NETOX" /> 
<REQUEST LoginAccountPassword="00JfDA.S0rxs6" LoginAccountIdentifier="XXXXX" InternalAccountIdentifier="XXXXX" RequestDatetime="2017-04-17T07:51:23"> 
<REQUEST_DATA> 
    <CREDIT_REQUEST MISMOVersionID = "2.3.1" RequestingPartyRequestedByName="1009" LenderCaseIdentifier="5010904"> 
    <CREDIT_REQUEST_DATA CreditRequestDateTime = "2017-04-17T07:51:23" CreditRequestType="Joint" CreditRepositoriesSelectedCount="0" CreditReportType="Merge" BorrowerID="BNUM2 BNUM1" CreditRequestID="CRQ1" CreditReportRequestActionType="Submit"> 
     <CREDIT_REPOSITORY_INCLUDED _TransUnionIndicator = "Y" _ExperianIndicator="Y" _EquifaxIndicator="Y"/> 
    </CREDIT_REQUEST_DATA> 
    <LOAN_APPLICATION> 
     <BORROWER BorrowerID = "BNUM2" JointAssetLiabilityReportingType="NotJointly" JointAssetBorrowerID="BNUM1" _PrintPositionType="Borrower" SchoolingYears="18" _SSN="500222000" _LastName="Homeowner" _HomeTelephoneNumber="9185454545" _FirstName="Mary" _BirthDate="19850202" _AgeAtApplicationYears="32"> 
     <_RESIDENCE _PostalCode = "74133" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="3214 E 30th Pl" BorrowerResidencyType="Current"/> 
     </BORROWER> 
     <BORROWER BorrowerID = "BNUM1" JointAssetLiabilityReportingType="NotJointly" JointAssetBorrowerID="BNUM2" _PrintPositionType="CoBorrower" SchoolingYears="21" _SSN="999405000" _LastName="Homeowner" _HomeTelephoneNumber="9185874547" _FirstName="John" _BirthDate="19780202" _AgeAtApplicationYears="39" MaritalStatusType="Unmarried"> 
     <_RESIDENCE _PostalCode = "74136" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="6600 S Yale Avenue" BorrowerResidencyType="Current"/> 
     </BORROWER> 
    </LOAN_APPLICATION> 
    </CREDIT_REQUEST> 
</REQUEST_DATA> 
</REQUEST> 

<MAILING_ADDRESS _PostalCode = "74137" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="1234 Fake St" BorrowerResidencyType="Current" _Bnum="2"/> 
<MAILING_ADDRESS _PostalCode = "74133" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="7777 S Memorial Drive" BorrowerResidencyType="Current" _Bnum="1"/> 

</REQUEST_GROUP> 

這個XSLT將產生結果。訣竅是使用身份轉換,獲取您需要的地址並將BNUM1轉換爲@ _Bnum ='1'。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> 

<!-- Store the addresses so we can get to them later--> 
<xsl:variable name='mailing' select='//MAILING_ADDRESS'/> 

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

<xsl:template match='BORROWER/_RESIDENCE'> 
    <!-- Convert "BNUM1" to just 1 and store in $addressid--> 
    <xsl:variable name='addressid' select='substring(ancestor::BORROWER/@BorrowerID, 5)'/> 

    <!-- use the address id to find the MAILING_ADDRESS--> 
    <xsl:variable name='address' select='$mailing[@_Bnum=$addressid]'/> 

    <xsl:element name='_RESIDENCE'> 
     <xsl:attribute name='addressid'><xsl:value-of select='$addressid'/></xsl:attribute> 
     <xsl:attribute name='_PostalCode'><xsl:value-of select='$address/@_PostalCode'/></xsl:attribute> 
     <xsl:attribute name='_State'><xsl:value-of select='$address/@_State'/></xsl:attribute> 
     <xsl:attribute name='_City'><xsl:value-of select='$address/@_City'/></xsl:attribute> 
     <xsl:attribute name='_StreetAddress'><xsl:value-of select='$address/@_StreetAddress'/></xsl:attribute> 
     <xsl:attribute name='BorrowerResidencyDurationYears'><xsl:value-of select='$address/@BorrowerResidencyDurationYears'/></xsl:attribute> 
     <xsl:attribute name='BorrowerResidencyType'><xsl:value-of select='$address/@BorrowerResidencyType'/></xsl:attribute> 
    </xsl:element> 
</xsl:template> 

</xsl:stylesheet> 

會產生這個XML結果

<?xml version="1.0"> 
<REQUEST_GROUP MISMOVersionID="2.3.1"> 
<REQUESTING_PARTY> 
<PREFERRED_RESPONSE _VersionIdentifier="2.3.1" _Format="XML"> 
</PREFERRED_RESPONSE> 
</REQUESTING_PARTY> 
<SUBMITTING_PARTY _Name="NETOX"> 
</SUBMITTING_PARTY> 
<REQUEST LoginAccountPassword="00JfDA.S0rxs6" LoginAccountIdentifier="XXXXX" InternalAccountIdentifier="XXXXX" RequestDatetime="2017-04-17T07:51:23"> 
<REQUEST_DATA> 
<CREDIT_REQUEST MISMOVersionID="2.3.1" RequestingPartyRequestedByName="1009" LenderCaseIdentifier="5010904"> 
<CREDIT_REQUEST_DATA CreditRequestDateTime="2017-04-17T07:51:23" CreditRequestType="Joint" CreditRepositoriesSelectedCount="0" CreditReportType="Merge" BorrowerID="BNUM2 BNUM1" CreditRequestID="CRQ1" CreditReportRequestActionType="Submit"> 
<CREDIT_REPOSITORY_INCLUDED _TransUnionIndicator="Y" _ExperianIndicator="Y" _EquifaxIndicator="Y"> 
</CREDIT_REPOSITORY_INCLUDED> 
</CREDIT_REQUEST_DATA> 
<LOAN_APPLICATION> 
<BORROWER BorrowerID="BNUM2" JointAssetLiabilityReportingType="NotJointly" JointAssetBorrowerID="BNUM1" _PrintPositionType="Borrower" SchoolingYears="18" _SSN="500222000" _LastName="Homeowner" _HomeTelephoneNumber="9185454545" _FirstName="Mary" _BirthDate="19850202" _AgeAtApplicationYears="32"> 
<_RESIDENCE addressid="2" _PostalCode="74137" _State="OK" _City="Tulsa" _StreetAddress="1234 Fake St" BorrowerResidencyDurationYears="6" BorrowerResidencyType="Current" /> 
</BORROWER> 
<BORROWER BorrowerID="BNUM1" JointAssetLiabilityReportingType="NotJointly" JointAssetBorrowerID="BNUM2" _PrintPositionType="CoBorrower" SchoolingYears="21" _SSN="999405000" _LastName="Homeowner" _HomeTelephoneNumber="9185874547" _FirstName="John" _BirthDate="19780202" _AgeAtApplicationYears="39" MaritalStatusType="Unmarried"> 
<_RESIDENCE addressid="1" _PostalCode="74133" _State="OK" _City="Tulsa" _StreetAddress="7777 S Memorial Drive" BorrowerResidencyDurationYears="6" BorrowerResidencyType="Current" /> 
</BORROWER> 
</LOAN_APPLICATION> 
</CREDIT_REQUEST> 
</REQUEST_DATA> 
</REQUEST> 
<MAILING_ADDRESS _PostalCode="74137" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="1234 Fake St" BorrowerResidencyType="Current" _Bnum="2"> 
</MAILING_ADDRESS> 
<MAILING_ADDRESS _PostalCode="74133" BorrowerResidencyDurationYears="6" _State="OK" _City="Tulsa" _StreetAddress="7777 S Memorial Drive" BorrowerResidencyType="Current" _Bnum="1"> 
</MAILING_ADDRESS> 
</REQUEST_GROUP> 
0

使用身份轉換與_RESIDENCE的覆蓋,這將在屬性複製從相應的MAILING_ADDRESS元素:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="_RESIDENCE"> 
    <xsl:variable name="residenceBnum" 
        select="substring(../@BorrowerID, 5)"/> 
    <xsl:copy> 
     <xsl:copy-of select="/REQUEST_GROUP 
          /MAILING_ADDRESS[@_Bnum = $residenceBnum]/@*"/> 
    </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

您可能希望如果您希望從新的_RESIDENCE元素中省略某些屬性,則可以爲屬性應用附加的過濾器。 (例如,你沒有指定,如果@_Bnum應該過來。)