Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How To Group and Count Distinct Values in XSL

FofanaJan 15 2019 — edited Jan 22 2019

Just to explain in short the context.

I am trying to have one template to apply to different XML.

The XML can have these 3 possibilities:

A/ Only one accountNumber then One AccountName

B/  Two accountNumbers with same AccountName

C/ Two accountNumbers with different accountNames

Now I need to set a condition to check how many different account names I have:

In situation A/ the count should give me 1

In situation B/ the count should give me 1

In situation C/ the count should give me 2

I have this:

<xsl:key name="groupByAccountNumber" match="invoice/accountInvoiceElements" use="accountName" />

But when I do this:

<xsl:when test="count(key('groupByAccountNumber',accountName)) > 1">

I get wrong number...

A simplified sample XML is :

<invoice>

<accountInvoiceElements>

<invoiceElements>

......

</invoiceElements>

<invoiceElements>

......

</invoiceElements>

<accountName>Network Category 1</accountName>

<accountNumber>CORCA000009</accountNumber>

         <isParent>0</isParent>

         <taxTotal>34.286</taxTotal>

         <totalAmount>265.726</totalAmount>

</accountInvoiceElements>

<accountInvoiceElements>

<invoiceElements>

......

</invoiceElements>

<invoiceElements>

......

</invoiceElements>

<accountName>Network Category 2</accountName>

        <accountNumber>CORCA000009</accountNumber>

        <isParent>1</isParent>

        <taxTotal>34.286</taxTotal>

        <totalAmount>265.726</totalAmount>

</accountInvoiceElements>

</invoice>

Any Help????

This post has been answered by tsuji on Jan 18 2019
Jump to Answer
Comments
Post Details
Added on Jan 15 2019
2 comments
2,347 views