0
votes

HI I am creating an XSLT file for transforming XML. I want to count records with condition

<Body>
    <BankAccountTable class="entity">          
      <AccountNum>123456789</AccountNum>          
      <BankChequeTable class="entity">
        <AccountID>101</AccountID>
        <AmountCur>40.00</AmountCur>
        <ChequeStatus>Payment</ChequeStatus>            
        <VendTable class="entity">
          <AccountNum>1</AccountNum>              
        </VendTable>            
      </BankChequeTable>
      <BankChequeTable class="entity">
        <AccountID>101</AccountID>
        <AmountCur>45.00</AmountCur>            
        <ChequeStatus>Payment</ChequeStatus>            
        <VendTable class="entity">
          <AccountNum>2</AccountNum>              
        </VendTable>            
      </BankChequeTable>
      <BankChequeTable class="entity">
        <AccountID>101</AccountID>
        <AmountCur>45.00</AmountCur>            
        <ChequeStatus>Void</ChequeStatus>            
        <VendTable class="entity">
          <AccountNum>2</AccountNum>              
        </VendTable>            
      </BankChequeTable>          
    </BankAccountTable>

Now i want to count BankAccountTable records where ChequeStatus must equals to Payment can any one suggest how to achieve this. I am using Xsl:stylesheet version="1.0". I am able to count all record by using this line of code:


<xsl:for-each select="/BankAccountTable"> <xsl:variable name="totalCount" select="count(child::BankChequeTable)"></xsl:variable>


but I want it with condition. for following example count must be equals to 2.

Any help will be appreciated.

Thanks

1

1 Answers

0
votes

You can count the records like this:

<xsl:variable name="totalCount" select="count(Body/BankAccountTable/BankChequeTable[ChequeStatus='Payment'])"/>

See it working here: https://xsltfiddle.liberty-development.net/naZYrpt