我有以下 XML
<ExternalAssessmentRequest >
<ApplicationData Lender="TEST">
<LiabilityList>
<RequestedLoan Identifier="New1" BaseAmount="250000">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
<Feature Code="SupaPackage"/>
</RequestedLoan>
<ExistingLoan Identifier="Existing1" Clearing="Yes" >
<Security RelatedIdentifier="Asset1"/>
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</ExistingLoan>
<OtherLiability Identifier="Liability1" CreditCard="Yes" >
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</OtherLiability>
<Expense Identifier="Expense1" Type="Transport" >
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</Expense>
</LiabilityList>
<AssetList>
<Asset Identifier="Asset1" Security="Yes" >
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</Asset>
<Fund Identifier="Fund1" Amount="1000" Description="Slush Fund"/>
</AssetList>
<IncomeList>
<Income Identifier="Income1" GrossAmount="80000" >
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</Income>
</IncomeList>
<ApplicantList>
<Household Children="0" AdditionalAdults="0" Postcode="2000" Description="1 Test St, Sydney" Boarding="Yes">
<Person Identifier="Applicant1" Name="John Test" />
<Person Identifier="Applicant2" Name="Jane Test" />
</Household>
<Company Identifier="Company1" Name="Tardis">
<Director RelatedIdentifier="Applicant1"/>
</Company>
</ApplicantList>
<FeeList>
<Fee Identifier="Fee1" Amount="100" PaidAmount="0" />
</FeeList>
</ApplicationData>
<AdditionalAssessment Lender="TESTLender">
<RequestedLoan Product="Supa Variable" ProductID="ProductA"/>
</AdditionalAssessment>
<AdditionalAssessment Lender="TEST1">
<RequestedLoan Product="Supa Variable" ProductID="ProductB"/>
</AdditionalAssessment>
<AdditionalAssessment Lender="TEST2">
<RequestedLoan Product="Supa Variable" ProductID="ProductC"/>
</AdditionalAssessment>
<AdditionalAssessment Lender="TEST3">
<RequestedLoan Product="Supa Variable" ProductID="ProductD"/>
</AdditionalAssessment>
<AdditionalAssessment Lender="TEST4">
<RequestedLoan Product="Supa Variable" ProductID="ProductD"/>
</AdditionalAssessment>
</ExternalAssessmentRequest>
我有这个样式表:
<?xml version="1.0" encoding="ascii"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">
<xsl:output omit-xml-declaration="yes" method="xml" encoding="UTF-8"/>
<!--remember the location of the additional assessment information-->
<xsl:variable name="additional" select="/*/AdditionalAssessment"/>
<xsl:template match="ApplicationData">
<!--preserve original data-->
<xsl:copy-of select="."/>
<!--now make duplicate-->
<ApplicationData>
<!--preserve data attributes-->
<xsl:copy-of select="@*"/>
<!--override with additional attributes-->
<xsl:copy-of select="$additional/@*"/>
<!--process children looking for modifications to attributes-->
<xsl:apply-templates select="node()" mode="overrideAttributes"/>
</ApplicationData>
</xsl:template>
<!--copy the element and override attributes form the additional assessment-->
<xsl:template match="*" mode="overrideAttributes">
<xsl:copy>
<!--preserve data attributes-->
<xsl:copy-of select="@*"/>
<!--override with additional attributes-->
<xsl:copy-of select="$additional/*[name(.)=name(current())]/@*"/>
<!--manipulate the descendants-->
<xsl:apply-templates mode="overrideAttributes"/>
</xsl:copy>
</xsl:template>
<!--remove the original additional assessment-->
<xsl:template match="AdditionalAssessment"/>
<xsl:template match="@*|node()">
<!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/ExternalAssessmentRequest">
<xsl:element name="ApplicationDataBatch">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
产生以下输出:
<ApplicationDataBatch>
<ApplicationData Lender="TEST">
<LiabilityList>
<RequestedLoan Identifier="New1" BaseAmount="250000">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
<Feature Code="SupaPackage"/>
</RequestedLoan>
<ExistingLoan Identifier="Existing1" Clearing="Yes">
<Security RelatedIdentifier="Asset1"/>
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</ExistingLoan>
<OtherLiability Identifier="Liability1" CreditCard="Yes">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</OtherLiability>
<Expense Identifier="Expense1" Type="Transport">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</Expense>
</LiabilityList>
<AssetList>
<Asset Identifier="Asset1" Security="Yes">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</Asset>
<Fund Identifier="Fund1" Amount="1000" Description="Slush Fund"/>
</AssetList>
<IncomeList>
<Income Identifier="Income1" GrossAmount="80000">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</Income>
</IncomeList>
<ApplicantList>
<Household Children="0" AdditionalAdults="0" Postcode="2000" Description="1 Test St, Sydney" Boarding="Yes">
<Person Identifier="Applicant1" Name="John Test"/>
<Person Identifier="Applicant2" Name="Jane Test"/>
</Household>
<Company Identifier="Company1" Name="Tardis">
<Director RelatedIdentifier="Applicant1"/>
</Company>
</ApplicantList>
<FeeList>
<Fee Identifier="Fee1" Amount="100" PaidAmount="0"/>
</FeeList>
</ApplicationData>
<ApplicationData Lender="TEST4">
<LiabilityList>
<RequestedLoan Identifier="New1" BaseAmount="250000" Product="Supa Variable" ProductID="ProductD">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
<Feature Code="SupaPackage"/>
</RequestedLoan>
<ExistingLoan Identifier="Existing1" Clearing="Yes">
<Security RelatedIdentifier="Asset1"/>
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</ExistingLoan>
<OtherLiability Identifier="Liability1" CreditCard="Yes">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</OtherLiability>
<Expense Identifier="Expense1" Type="Transport">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</Expense>
</LiabilityList>
<AssetList>
<Asset Identifier="Asset1" Security="Yes">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</Asset>
<Fund Identifier="Fund1" Amount="1000" Description="Slush Fund"/>
</AssetList>
<IncomeList>
<Income Identifier="Income1" GrossAmount="80000">
<Applicant RelatedIdentifier="Applicant1" Percentage="0.5"/>
<Applicant RelatedIdentifier="Applicant2" Percentage="0.5"/>
</Income>
</IncomeList>
<ApplicantList>
<Household Children="0" AdditionalAdults="0" Postcode="2000" Description="1 Test St, Sydney" Boarding="Yes">
<Person Identifier="Applicant1" Name="John Test"/>
<Person Identifier="Applicant2" Name="Jane Test"/>
</Household>
<Company Identifier="Company1" Name="Tardis">
<Director RelatedIdentifier="Applicant1"/>
</Company>
</ApplicantList>
<FeeList>
<Fee Identifier="Fee1" Amount="100" PaidAmount="0"/>
</FeeList>
</ApplicationData>
</ApplicationDataBatch>
一切都是应有的,只是缺少一件事。我需要为每个 AdditionalAssessment 节点创建一个 ApplicationData 节点。当前样式表只创建一个而不是 5(+1 原始应用程序数据)。样式表需要为每个 AdditionalAssessment 节点创建 ApplicationData 节点,只需更改每个 Additional Assessment 中指定的元素。