Reputation: 293
My XML structure as is below
<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>
I am looking for output like below
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
I want to know how I can match the "AdditionalPvtDetails" items like Name,Geneder,Identification for each "account" information and format the output as shown above.. basically, "AdditinalPvtDetails" and "account" has to be joined by "Id"...
Upvotes: 0
Views: 91
Reputation: 70618
I believe you could make use of xsl:key here to look up the AdditionalPvtDetails elements whilst positioned on Account elements
<xsl:key name="additional" match="AdditionalPvtDetails" use="@id" />
This created a key named additional which can be used to look-up AdditionalPvtDetails using their id attribute. For example, assuming you were positioned on an Account element, you could look up the gender of the account as follows:
<xsl:value-of select="key('additional', @id)/PvtGender" />
As a simple example, consider this 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>
When applied to your sample XML, the following is returned:
AccountID: 110095115 Gender: FEMALE
AccountID: 110095163 Gender: FEMALE
AccountID: 110095180 Gender: FEMALE
Upvotes: 2