We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,842 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

distinct values using xpath

1. I want to take unique district values from the below xml. How to do it in XPATH?
2. I want to take unique taluk values and district name="xyz". what is the xpath expression?

XML structure:

<?xml version="1.0" encoding="utf-8"?>
<imageData>
<row>
<slno>1</slno>
<sitecode>001</sitecode>
<sitename>Mel Sittamur</sitename>
<photono>001_001_001.jpg</photono>
<photodate>07-09-2008</photodate>
<district>Villupuram</district>
<taluk>Senji</taluk>
<monument><![CDATA[Jain Temple, Sri Parsvanadha]]></monument>
<subject><![CDATA[Tower]]></subject>
<description><![CDATA[Yet to Provide the data ]]></description>
</row>
<row>
<slno>2</slno>
<sitecode>001</sitecode>
<sitename>Mel Sittamur</sitename>
<photono>001_001_002.jpg</photono>
<photodate>07-09-2008</photodate>
<district>Villupuram</district>
<taluk>Senji</taluk>
<monument><![CDATA[Jain Temple, Sri Parsvanadha]]></monument>
<subject><![CDATA[Tower detail]]></subject>
<description><![CDATA[Yet to Provide the data ]]></description>
</row>
<row>
<slno>3</slno>
<sitecode>001</sitecode>
<sitename>Mel Sittamur</sitename>
<photono>001_001_003.jpg</photono>
<photodate>07-09-2008</photodate>
<district>xyz</district>
<taluk>Senji</taluk>
<monument><![CDATA[Jain Temple, Sri Parsvanadha]]></monument>
<subject><![CDATA[Saraswati]]></subject>
<description><![CDATA[Yet to Provide the data ]]></description>
</row>

.....

</imageData>

3
Contributors
8
Replies
3 Weeks
Discussion Span
1 Year Ago
Last Updated
9
Views
iswariak
Newbie Poster
4 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I'm not sure if I have understood your question correctly. Try the below:

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

<xsl:output method="xml"/>

<xsl:template match="imageData">
<xsl:for-each-group select="row" group-by="district">
<p><xsl:value-of select="current-grouping-key()"/></p>
<xsl:for-each-group select="current-group()" group-by="taluk">
<p><xsl:value-of select="current-grouping-key()"/></p>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>

If this is not what you expect, then post the expected output here.

mrame
Light Poster
37 posts since Feb 2011
Reputation Points: 10
Solved Threads: 4
Skill Endorsements: 0

I want to access the result using xpath and xml dom.. Just i need the xpath expressions to retrieve the results.

thanks.

I'm not sure if I have understood your question correctly. Try the below:

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

<xsl:output method="xml"/>

<xsl:template match="imageData">
<xsl:for-each-group select="row" group-by="district">
<p><xsl:value-of select="current-grouping-key()"/></p>
<xsl:for-each-group select="current-group()" group-by="taluk">
<p><xsl:value-of select="current-grouping-key()"/></p>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>

If this is not what you expect, then post the expected output here.

iswariak
Newbie Poster
4 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Below xpath function would help:

<xsl:value-of select="distinct-values(//row/district)"/>

Just use the "distinct-values(//row/district)"

mrame
Light Poster
37 posts since Feb 2011
Reputation Points: 10
Solved Threads: 4
Skill Endorsements: 0

Below xpath function would help:

<xsl:value-of select="distinct-values(//row/district)"/>

Just use the "distinct-values(//row/district)"

thanks for the expression.

I want to take unique taluk values and district name="xyz". what is the xpath expression?

iswariak
Newbie Poster
4 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Unique taluk values:

distinct-values(//row/taluk)

I still dont understand your question. Okay tell what would be the output from your question (I want to take unique taluk values and district name="xyz"). is it Senji, or ...

mrame
Light Poster
37 posts since Feb 2011
Reputation Points: 10
Solved Threads: 4
Skill Endorsements: 0

Unique taluk values:

distinct-values(//row/taluk)

I still dont understand your question. Okay tell what would be the output from your question (I want to take unique taluk values and district name="xyz"). is it Senji, or ...

distinct-values(//row/taluk) will give all distinct taluk values irrespective of the district name.

But I want,

When a user selects a district, I have to query the xml to get the distinct taluk values of the selected district.

iswariak
Newbie Poster
4 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Would the below work:

<xsl:value-of select="distinct-values(//row/taluk[preceding-sibling::district[.='xyz'][1]])"/>
mrame
Light Poster
37 posts since Feb 2011
Reputation Points: 10
Solved Threads: 4
Skill Endorsements: 0

Ask Jeeves a question and Jeeves will answer it.
Britain's leading question-and-answer
service is as ready
for your questions as ever.Try it now.
http://ask.co.uk

zaibi403
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1541 seconds using 2.73MB