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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:18:58+00:00 2026-06-08T06:18:58+00:00

Hello I am new to xml and would like to compare some values using

  • 0

Hello I am new to xml and would like to compare some values using an xsl stylesheet

`<a>
 <b>   <name>foo</name>   </b>
 <b>   <name>bar</name>   </b>
 <b>   <name>fred</name>  </b>
 <b>   <name>fred</name>  </b>
 </a>`

I would like to write a style sheet that checks all the b nodes and returns the values that have the same value so using the simple example above i would like the output to resemble :
“Your duplicate strings are fred”

I have used a for each loop to return all the values but comparing the names and returning the duplicates has eluded me.If possible i would like to achieve the comparison by the use of a while type loop.

Thank you for any help.

  • 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-06-08T06:19:01+00:00Added an answer on June 8, 2026 at 6:19 am

    An <xsl:key>-based solution:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:key name="kName" match="b/name" use="text()" />
    
      <xsl:template match="/">
        <xsl:for-each select="//b/name">
          <xsl:if test="count(key('kName', text())) &gt; 1">
            <xsl:value-of select="concat('Your duplicate is: ', text(), '&#xA;')" />
          </xsl:if>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>
    

    For large input documents this will be more efficient than a solution that uses a preceding:: check.

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

Sidebar

Related Questions

Hello I have a xml file from whihc i would like ot have a
Hello I'm new to ontologies, my assignment is to create an ontology using Protege
I would like to develop an external website using Facebook Connect instead of an
I would like to marshall Java objects into XML and vice-versa from within an
The manual page for XML::Parser::Style::Objects is horrible. A simple hello world style program would
Here's some C# code: var sb = new StringBuilder(); var w = XmlWriter.Create(sb); w.WriteStartElement(hello);
.NET's XmlTextWriter creates invalid xml files. In XML, some control characters are allowed, like
class Hello @hello = hello def display puts @hello end end h = Hello.new
hello im new to python and have been reading over the documentation and am
Hello.Am new to ios development.What have to do for NSOpenPanel to work in the

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.