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 7069281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:25:36+00:00 2026-05-28T05:25:36+00:00

Each new problem that I think I will be able to solve, it turns

  • 0

Each new problem that I think I will be able to solve, it turns out that I can’t.
So, with the following XML I would like to know how many different nodes are there that have a different @num attribute. Perhaps easier to understand looking at the wished output.

Initial XML code

<data>
    <prot seq="AAA">
        <node num="2">1345</node>
        <node num="2">11245</node>
        <node num="2">112w45</node>
        <node num="7">88885</node>
    </prot>
    <prot seq="BBB">
        <node num="2">678</node>
        <node num="2">456</node>
        <node num="7">4w56</node>
        <node num="7">6666</node>
    </prot>
    <prot seq="CCC">
        <node num="2">111</node>
        <node num="2">222</node>
        <node num="2">22w2</node>
        <node num="7">333</node>
        <node num="10">3433</node>
    </prot>
</data>

And the wished output, so that it expresses how many different “num”s are there

<root>
<num>2</num>
<num>7</num>
<num>10</num>
</root>

I guess it can be done (as it seems to be always the case) with muenchian grouping. I just can’t see it.

Thanks!

  • 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-28T05:25:36+00:00Added an answer on May 28, 2026 at 5:25 am

    I’m new to Meunchian, too. Here’s my solution:

    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <xsl:output method="xml" indent="yes"/>
      <xsl:key name="dupes" match="node" use="@num"/>
      <xsl:template match="/">
        <root>
          <xsl:apply-templates select="//node[generate-id() =
               generate-id(key('dupes', @num)[1])]"/>
        </root>
      </xsl:template>
    
      <xsl:template match="node">
        <num val="{.}">
          <xsl:value-of select="@num"/>
        </num>
      </xsl:template>
    </xsl:stylesheet>
    

    When I I run this with xsltproc:

    ~ zacharyyoung$ xsltproc so.xsl so.xml
    <?xml version="1.0"?>
    <root>
      <num val="1345">2</num>
      <num val="88885">7</num>
      <num val="3433">10</num>
    </root>
    

    I added the val="{.}" bit to show which node is being used from the key grouping. If we change ...key('dupes', @num)[1]... to ...key('dupes', @num)[last()]... we can see the difference here:

    <root>
      <num val="22w2">2</num>
      <num val="333">7</num>
      <num val="3433">10</num>
    </root>
    

    For every group of nodes with corresponding values (2,7,10, etc…), the last() node in each group is selected, versus the first [1] in the previous example.

    I hope this helps.

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

Sidebar

Related Questions

the following code (from a database object created for each new view): -(void)update:(NSString *)queryText{
I parse an xml file containing books, for each new node I go: Book
Do languages become more verbose as they mature? It feels like each new version
I'm new to C++ and trying to implement a turtle emulator that will read
I have a head aching problem that I can't seem to find an easy
I am trying to make a blackjack game where before each new round, the
In C++, I've written a mathematical program (for diffusion limited aggregation) where each new
I have some ctypes bindings, and for each body.New I should call body.Free. The
@search_results = Array.new duplicates = Set.new results.each { |result| @search_results.push(result) unless duplicates.add?(result[:url]) } This
I'm trying to create a new div each time a text field contained in

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.