-1

Input:

    <data>

      <root>
        <name>A</name>
        <name>B</name>
      </root>

      <root>
        <name>C</name>
        <name>D</name>
        <name>A</name>
      </root>

    </data>

Output:

<data>
      <root>
        <name>A</name>
        <name>B</name>
        <name>C</name>
        <name>D</name>
      </root>
</data>

User enters data in name element of two different nodes. So i want a XSLT which combines two nodes and removes the duplicate values. I tried, but it is not working. Please help me.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • 2
    Can you edit your question to show the XSLT you have tried, even if it is not working. Thank you! – Tim C May 27 '16 at 12:54
  • See if http://stackoverflow.com/questions/6768387/removing-duplicates-in-xml-with-xslt helps you – kjhughes May 27 '16 at 13:07
  • Any problem that involves removing duplicates is going to have a very different solution in XSLT 1.0 and 2.0. Because both versions are very widely used, you really need to say which you are using. (And the 2.0 solution is going to be much easier, so use 2.0 if you possibly can.) – Michael Kay May 27 '16 at 14:10
  • @MichaelKay Kay: I am using XSLT 1.0. Please help me. – Rachit Jain May 30 '16 at 04:59
  • Sorry, I don't do grouping queries in XSLT 1.0. Too much like hard work, and since I've been using 2.0 since about 2003, one forgets. – Michael Kay May 30 '16 at 19:58
  • @kjhughes : It is completely different. Can you suggest some solution for my problem. – Rachit Jain May 31 '16 at 05:14
  • @Michael Kay : What is the solution in XSLT 2.0? I can use this also. – Rachit Jain May 31 '16 at 05:35

1 Answers1

0

In XSLT 2.0 it's simply

<xsl:for-each-group select="/data/root/name" group-by=".">
  <xsl:copy-of select="current-group()[1]"/>
</xsl:for-each-group>
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Its not working. Can you suggest some other solution. – Rachit Jain Jun 06 '16 at 09:09
  • 1
    Is that your normal approach to problem solving? If it doesn't work, try something else? If so, you need to rethink your approach. If something doesn't work, you need to find out why, and the first step in that is to examine the symptoms of the failure: when you say "its not working", how exactly does it fail? – Michael Kay Jun 06 '16 at 10:05