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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:33:13+00:00 2026-05-21T15:33:13+00:00

I have the following input: <?xml version=1.0 encoding=utf-8?> <NewTerms> <newTerm>XPath</newTerm> <newTerm>AutoValue</newTerm> <newTerm>XPath</newTerm> <newTerm>context</newTerm> <newTerm>AutoValue</newTerm>

  • 0

I have the following input:

<?xml version="1.0" encoding="utf-8"?>
<NewTerms>
  <newTerm>XPath</newTerm>
  <newTerm>AutoValue</newTerm>
  <newTerm>XPath</newTerm>
  <newTerm>context</newTerm>
  <newTerm>AutoValue</newTerm>
  <newTerm>language files</newTerm>
   <newTerm>AutoValue</newTerm>
  <newTerm>.NET</newTerm>
  <newTerm>XPath</newTerm>
</NewTerms>

I want to sort it, and it functions perfectly with the following:

  <xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>

  <xsl:template match="@*|node()">  
    <xsl:copy>
      <xsl:apply-templates select="@*|node()">
        <xsl:sort select="."/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

The problem is I am getting (Obviously) a sorted output list with the elements with same values in repetition (e.g XPath, AutoValue). I want to have the sorted list without the repeated values. That is, I want to have each value only once in the sorted XML output.

Please any suggestions?

  • 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-21T15:33:14+00:00Added an answer on May 21, 2026 at 3:33 pm

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kNewTermByValue" match="newTerm" use="."/>
        <xsl:template match="node()|@*">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="NewTerms">
            <xsl:copy>
                <xsl:apply-templates select="@*"/>
                <xsl:apply-templates
                 select="newTerm[count(.|key('kNewTermByValue',.)[1])=1]">
                    <xsl:sort/>
                </xsl:apply-templates>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <NewTerms xp_0:noNamespaceSchemaLocation="../XSD\CC-CustomDocuTags.xsd" xmlns:xp_0="http://www.w3.org/2001/XMLSchema-instance">
        <newTerm>.NET</newTerm>
        <newTerm>AutoValue</newTerm>
        <newTerm>context</newTerm>
        <newTerm>EPF</newTerm>
        <newTerm>language files</newTerm>
        <newTerm>XPath</newTerm>
    </NewTerms>
    

    Note: Do not sort attributes and children together because you can’t output an attribute after you output a children.

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

Sidebar

Related Questions

I have the following HTML code: <?xml version=1.0 encoding=utf-8 ?> <!DOCTYPE html PUBLIC -//W3C//DTD
I have the following XML file: <?xml version='1.0' encoding='utf-8'?> <Answers> <Question1 q=What is your
I have the following XML file: <?xml version='1.0' encoding='utf-8'?> <Answers> <Question1 q=What is your
I have a input file Main.xml <?xml version=1.0 encoding=utf-8 ?> <Employees> <Employee> <id name=id>1</id>
I have a question. My input XML looks like <?xml version=1.0 encoding=UTF-8?> <Text> <Message>this
I have two flows configured in the following way: <?xml version=1.0 encoding=UTF-8?> <flow xmlns=http://www.springframework.org/schema/webflow
i have following xml file as input .... <?xml version=1.0 encoding=ISO-8859-1?> <T0020 xsi:schemaLocation=http://www.safersys.org/namespaces/T0020V1 T0020V1.xsd
I have the following small file to reproduce the warning: <?xml version=1.0 encoding=UTF-8?> <beans
I have a style sheet like this <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:param
I have the following xml input: <data> <parent Id=1 value=ParentOne> <child x=1 y=2 />

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.