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>

Recommended Answers

All 8 Replies

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.

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.

Below xpath function would help:

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

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

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?

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 ...

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.

Would the below work:

<xsl:value-of select="distinct-values(//row/taluk[preceding-sibling::district[.='xyz'][1]])"/>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.