2012-02-01 93 views
0

我的XML结构,低于XSL - 基于其他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 “项目,如名称,发生器,每个”帐户“信息的识别和格式输出如上所示..基本上,”AdditinalPvtDetails“和”帐户“必须加入”Id“...

回答

2

我相信你可以让XSL的使用:关键这里来查找AdditionalPvtDetails元素,而位于账户元素

<xsl:key name="additional" match="AdditionalPvtDetails" use="@id" /> 

这创建了一个名为关键额外可用于查找AdditionalPvtDetails使用它们的id属性。例如,假设你是定位在帐户元素上,你可以查找该帐户的性别如下:

<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, '&#13;')" /> 
    </xsl:template> 
</xsl:stylesheet> 

当应用到您的示例XML,将返回以下内容:

AccountID: 110095115 Gender: FEMALE 
AccountID: 110095163 Gender: FEMALE 
AccountID: 110095180 Gender: FEMALE