2012-02-01 92 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