Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1070731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:36:33+00:00 2026-05-16T20:36:33+00:00

Stuck a bit with the following and would love some ideas/pointers in the right

  • 0

Stuck a bit with the following and would love some ideas/pointers in the right direction. I have the following XML:

<RecordsCollection>
  <CustomerRecord>
    <customerId>12345</customerId>
    <currency>USD</currency>
  </CustomerRecord>
  <CustomerRecord>
    <customerId>12345</customerId>
    <currency>USD</currency>
  </CustomerRecord>
  <CustomerRecord>
    <customerId>90210</customerId>
    <currency>USD</currency>
  </CustomerRecord>
</RecordsCollection>

What I need to accomplish is to simply produce a single value containing the count of unique currency elements contained with a unique account number. To explain further, the example above contains two entries with the same currency (USD) for the same account number (12345), so they’re counted as 1 and another entry which is also counted as 1. Hence, the example above should result in:

<totalCount>2</totalCount>

Any idea as to how to achieve it? I know how to select distinct account numbers, but what I don’t seem to be able to wrap my head around is how to count the distinct currencies within each account.

Lastly, this has to be done using XSLT 1.0 … any thoughts would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:36:34+00:00Added an answer on May 16, 2026 at 8:36 pm

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kRecordByIdAndCurr" match="CustomerRecord"
                 use="concat(customerId,'++',currency)"/>
        <xsl:template match="/">
            <totalCount>
                <xsl:value-of select="count(*/*
                                             [count(.|key('kRecordByIdAndCurr',
                                                          concat(customerId,
                                                                 '++',
                                                                 currency)
                                                         )[1]
                                                   )=1])"/>
            </totalCount>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <totalCount>2</totalCount>
    

    Note: Just grouping by customerId and currency string value.

    Edit: Sorry, miss the customerId before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.