我有以下xml:
<? 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 :(得分: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 =&#39; 1&#39;。
<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>
答案 1 :(得分: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
是否应该过来。)