我的XML结构如下所示
<AccountDetails>
<AdditionalPvtDetails seq="1" id="110095115">
<PvtClientFullname>YYYY</PvtClientFullname>
<PvtGender>FEMALE</PvtGender>
<PvtIdentification>
<PvtVoterID>KXF1067981</PvtVoterID>
</PvtIdentification>
<PvtAddress>
<AdditionalAddressDetails seq="1">
<Addressline>ST2</Addressline>
<State>OH</State>
<PIN>56708</PIN>
</AdditionalAddressDetails>
</PvtAddress>
</AdditionalPvtDetails>
<AdditionalPvtDetails seq="2" id="110095163">
<PvtClientFullname>YYYY </PvtClientFullname>
<PvtGender>FEMALE</PvtGender>
<PvtIdentification/>
<PvtAddress>
<AdditionalAddressDetails seq="1">
<Addressline>ST2</Addressline>
<State>OH</State>
<PIN>56708</PIN>
</AdditionalAddressDetails>
</PvtAddress>
</AdditionalPvtDetails>
<AdditionalPvtDetails seq="3" id="110095180">
<PvtClientFullname>YYYY</PvtClientFullname>
<PvtGender>FEMALE</PvtGender>
<PvtIdentification/>
<PvtAddress>
<AdditionalAddressDetails seq="1">
<Addressline>ST1</Addressline>
<State>OH</State>
<PIN>56708</PIN>
</AdditionalAddressDetails>
</PvtAddress>
</AdditionalPvtDetails>
<Account seq="1" id="110095115" ReportedDate="2011-07-11">
<AccountNumber> 8601N70201</AccountNumber>
<CurrentBalance>0</CurrentBalance>
<Institution>Pvt Limited</Institution>
<DisbursedAmount>12000</DisbursedAmount>
<LoanPurpose>510</LoanPurpose>
<SanctionAmount>12000</SanctionAmount>
<DateReported>2011-07-11</DateReported>
<DateOpened>2009-09-24</DateOpened>
<DateClosed>2010-09-09</DateClosed>
<LoanCycleID>01</LoanCycleID>
<DateSanctioned>2009-09-18</DateSanctioned>
<DateApplied>2009-09-17</DateApplied>
<AppliedAmount>12000</AppliedAmount>
<NoOfInstallments>50</NoOfInstallments>
<RepaymentTenure>Weekly</RepaymentTenure>
<InstallmentAmount>276</InstallmentAmount>
<KeyPerson>
<Name>XXX</Name>
<RelationType>Husband</RelationType>
</KeyPerson>
<Nominee>
<Name/>
<RelationType/>
</Nominee>
<AccountStatus>Closed Account</AccountStatus>
</Account>
<Account seq="2" id="110095163" ReportedDate="2011-07-11">
<AccountNumber> 8601N70202</AccountNumber>
<CurrentBalance>4400</CurrentBalance>
<Institution>Pvt Limited</Institution>
<DisbursedAmount>20000</DisbursedAmount>
<LoanPurpose>302</LoanPurpose>
<SanctionAmount>20000</SanctionAmount>
<DateReported>2011-07-11</DateReported>
<DateOpened>2010-09-30</DateOpened>
<LoanCycleID>02</LoanCycleID>
<DateSanctioned>2010-09-24</DateSanctioned>
<DateApplied>2010-09-23</DateApplied>
<AppliedAmount>20000</AppliedAmount>
<NoOfInstallments>50</NoOfInstallments>
<RepaymentTenure>Weekly</RepaymentTenure>
<InstallmentAmount>460</InstallmentAmount>
<KeyPerson>
<Name>XXX</Name>
<RelationType>Husband</RelationType>
</KeyPerson>
<Nominee>
<Name/>
<RelationType/>
</Nominee>
<AccountStatus>Current Account</AccountStatus>
</Account>
<Account seq="3" id="110095180" ReportedDate="2011-07-11">
<AccountNumber> 8601N7201</AccountNumber>
<CurrentBalance>0</CurrentBalance>
<Institution>Pvt Limited</Institution>
<DisbursedAmount>4000</DisbursedAmount>
<LoanPurpose>510</LoanPurpose>
<SanctionAmount>4000</SanctionAmount>
<DateReported>2011-07-11</DateReported>
<DateOpened>2010-03-04</DateOpened>
<DateClosed>2011-02-17</DateClosed>
<LoanCycleID>01</LoanCycleID>
<DateSanctioned>2010-02-19</DateSanctioned>
<DateApplied>2010-02-18</DateApplied>
<AppliedAmount>4000</AppliedAmount>
<NoOfInstallments>50</NoOfInstallments>
<RepaymentTenure>Weekly</RepaymentTenure>
<InstallmentAmount>92</InstallmentAmount>
<KeyPerson>
<Name>XXX</Name>
<RelationType>Husband</RelationType>
</KeyPerson>
<Nominee>
<Name/>
<RelationType/>
</Nominee>
<AccountStatus>Closed Account</AccountStatus>
</Account>
</AccountDetails>
我正在寻找下面的输出
ID:110095115 Name :YYYY Account number : 8601N70201 Status : Closed Account No.Of Install:50
ID:110095163 Name :YYYY Account number : 8601N70202 Status : Current Account No.Of Install:50
我想知道如何匹配“AdditionalPvtDetails”项目,如姓名,Geneder,身份证明每个“帐户”信息,并格式化输出,如上所示..基本上,“AdditinalPvtDetails”和“account”必须加入通过“Id”...
答案 0 :(得分:2)
我相信您可以在此处使用 xsl:key 查找位于帐户元素
上的 AdditionalPvtDetails 元素<xsl:key name="additional" match="AdditionalPvtDetails" use="@id" />
这会创建一个名为附加的密钥,可用于使用 id 属性查找 AdditionalPvtDetails 。例如,假设您位于帐户元素上,则可以按如下方式查找帐户的性别:
<xsl:value-of select="key('additional', @id)/PvtGender" />
举一个简单的例子,考虑一下这个XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes"/>
<xsl:key name="additional" match="AdditionalPvtDetails" use="@id" />
<xsl:template match="/">
<xsl:apply-templates select="AccountDetails/Account" />
</xsl:template>
<xsl:template match="Account">
<xsl:value-of select="concat('AccountID: ', @id, ' ')" />
<xsl:value-of select="concat('Gender: ', key('additional', @id)/PvtGender, ' ')" />
</xsl:template>
</xsl:stylesheet>
当应用于您的示例XML时,将返回以下内容:
AccountID: 110095115 Gender: FEMALE
AccountID: 110095163 Gender: FEMALE
AccountID: 110095180 Gender: FEMALE