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!

Grouping by certain node but ordering by another descending

FofanaNov 13 2018 — edited Nov 22 2018

Hi, I don't really know which title to give to my question....

I have this sample XML:

   <lineItems>

              <code>135</code>

              <description>ABC COMMUNICATION SERVICES</description>

              <taxAmount>3.500</taxAmount>

  </lineItems>

   <lineItems>

              <code>253</code>

              <description>LOCAL COMMUNICATIONS SERVICES</description>

              <taxAmount>2.800</taxAmount>

  </lineItems>

   <lineItems>

              <code>135</code>

              <description>ABC COMMUNICATIONS SERVICES</description>

              <taxAmount>12.500</taxAmount>

  </lineItems>

   <lineItems>

              <code>253</code>

              <description>LOCAL COMMUNICATIONS SERVICES</description>

              <taxAmount>2.400</taxAmount>

  </lineItems>

I need to group by code and add the amount together using this sample code but for for the code 135 choose the second description

<xsl:for-each select=".//taxLineItem/lineItems[generate-id(.)=generate-id(key('tax-by-address-description', concat(ancestor::accountInvoiceElements/accountId, code))[1])]">

                    <xsl:sort select="description" />

                        <fo:table-row>

                            <fo:table-cell >

                                <fo:block >

                                      <xsl:value-of select="description"  />

                                <fo:block >

                             </fo:table-cell >

                             <fo:table-cell >

                                 <fo:block >

                                      <xsl:value-of select="sum(key('tax-by-address-description', concat(ancestor::accountInvoiceElements/accountId, code))/taxAmount)" />

                                <fo:block >

                              </fo:table-cell >

                         </fo:table-row>

          ............................

          ..........................

I am getting this result:

ABC COMMUNICATION SERVICES            ................. 16.00

  LOCAL COMMUNICATIONS SERVICES     ..................  5.20

But I want to have this:

  ABC COMMUNICATIONS SERVICES         ................. 16.00

  LOCAL COMMUNICATIONS SERVICES    ..................  5.20

I thought of using order = "descending" but it only applies the order on the whole list not selecting exactly the desired description under same code

Any idea?

Thanks

Comments
Post Details
Added on Nov 13 2018
4 comments
240 views