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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:11:17+00:00 2026-05-13T17:11:17+00:00

I want to use XSLT to transform a set of documents into one structure.

  • 0

I want to use XSLT to transform a set of documents into one structure. I have the transformation working correctly to concatenate the documents. I don’t know, however, whether the the documents have duplicate entries in them, which I will need to remove.

I need to know how to remove these duplicates (if they exist) by an id attribute. All duplicates will have the same id. I know it will have something to do with keys and generate-id functions.

<root>
    <item id="1001">A</item>
    <item id="1003">C</item>
    <item id="1004">D</item>
    <item id="1002">B</item>
    <item id="1001">A</item>
    <item id="1003">C</item>
    <item id="1004">D</item>
    <item id="1005">E</item>
</root>

I need an XSLT 1.0 transformation for the above, based on the following…

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

Also, would someone be able to explain how it works to me too? Bit of a noob…

Thanks in advance…

  • 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-13T17:11:18+00:00Added an answer on May 13, 2026 at 5:11 pm

    Commonly solutions are presented with the use of generate-id() but personally I prefer a slightly different variation that doesn’t use generate-id:-

    <xsl:key name="items" match="item" use="@id" />
    
    <xsl:template match="root">
        <root>
            <xsl:copy-of select="item[count(key('items',@id)[1]|.)=1]" />
        </root>
    </xsl:template>
    

    First you create a key which holds the all item elements using the id attribute as the lookup key. key generates an efficient index which can be used to look up items.

    The technique relies on the fact that when create a node-set using the | operator you get a unique set of nodes. In other words if the same node is found on both sides of the | operator it only appears in the resulting set once.

    The expression:-

     key('items',@id)
    

    Will return the set of item nodes that have a specific ID. So:-

     key('items',@id)[1]
    

    will return only one of the nodes that were found have that specific ID and is repeatable (that is using this expression repeatedly always returns the same node).

    Hence the expression:-

     count(key('items',@id)[1]|.)=1
    

    is can only be true for one item node with a specific id value.

    The copy-of therefore makes a deep copy of only one item node having a distinct id.

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

Sidebar

Related Questions

Is it possible to use XSLT to transform XML into something other than XML?
I have an xml element: <myElement>item1 item2 item3</myElement> I want to use XSLT to
I would like to use xslt to transform an xml file into an almost
I have an XSLT like below, and want to use apply-templates inside the xsl:for-each
I want to create conditional comments in XSLT. But when I use this: <!--
i want use some data from a website with web service. i have a
I don't want use old Visual Basic methods in my code, and I'm confused
I want to transform (with jquery.xslt.js) xml to be preserving tags in text nodes.
I have the following line of xml that I'm trying transform using XSLT but
I'm working with xslt for the first time. I have 2.0, but that's about

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.