This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSLT/XPath - Find unique text node value

 
Raymond Law
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following XML and want to retreive unique text node. Can xPath/XSLT achieve that??
<root>
<Dept>IS</Dept>
<Dept>AD</Dept>
<Dept>IS</Dept>
<Dept>HR</Dept>
<Dept>RD</Dept>
<Dept>HR</Dept>
</root>
Result:
IS
AD
HR
RD
 
Steven Broadbent
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to retrieve all distinct values?
I think this is possible using axes
 
Micheal Jacob
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Here is the code. But in this i have faced one problem. The problem is,any axis looks on the original source document, not the logical xml document after ascending.
so this piece of code will fetch the unique values when it is in ascending order.


This xsl look upon the previous given xml.
Let's wait for others view on this.
Micheal
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a much simpler solution:
 
Mahesh Chalil
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the Key mechanism it will be more simpler.

Thanks
-Mahesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic