Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Select unique values using xsl

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 11-05-2010
Member
 
Join Date: Mar 2010
Posts: 197
Select unique values using xsl
  

Hello,
I have an xsl file with me that list all the applications. It has multiple cases, then problem is that the same applicant name is repeated that is there is a duplication in the result. I would like to get the result with unique values using xsl.
Here is what I have tried till now
Code:
<th>App</th>
</tr>
 
<xsl:for-each select="the url or the path you have set">
 
	<xsl:sort select="appcnt" order="asc"	/>
 
<tr>
<td>
<a href="the url of the "><xsl:value-of select="appcnt"/></a>
</td>
</tr>

Reply With Quote
  #2  
Old 11-05-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Select unique values using xsl

Hello,
If you need to extract the values for xsl file then here is the code for it
Code:
...
<xsl:key nm="nm" match="nm" use="@frst"/>
<xsl:tmp match="/">
<xsl:for-each select="//nm[generate-id() = generate-id(key('nm',@frst)[1])]">
<xsl:value-of select="@frst"/>
</xsl:for-each>
</xsl:tmp>
...
Reply With Quote
  #3  
Old 11-05-2010
Member
 
Join Date: Nov 2009
Posts: 347
Re: Select unique values using xsl

Hello,
If you need an xsl result then you xml file should look similar to this
Code:
<?xml version="1.0" ?>
<clebrts>
 <celbrit>
  <name first="test" last="lasttest" />
  <birthdate value="date" />
 </celbrit>
 <celbrit>
  <name first="test2" last="ltest3" />
  <birthdate value="date" />
 </celbrit>
 <celbrit>
  <name first="test" last="ltest2" />
  <birthdate value="date" />
 </celbrit>
</clebrts>
Reply With Quote
  #4  
Old 11-05-2010
Member
 
Join Date: Nov 2009
Posts: 359
Re: Select unique values using xsl

Hello,
For extracting unique content from xsl file please take a look at the code below
Code:
<xsl:param name="ctest">all</xsl:param>
<xsl:key name="unqcatky" match="item" use="./catgry"/>
 
<select name="ctest">
<option value="all">all</option>
<xsl:for-each select="//item[generate-id() = generate-id(key('unqcatky', ./catgry))]">
<xsl:choose>
<xsl:when test="$ctest = catgry">
<option selected="{catgry}"><xsl:value-of select="catgry"/></option>
</xsl:when>
<xsl:otherwise>
<option value="{catgry}"><xsl:value-of select="catgry"/></option>
</xsl:otherwise>
</xsl:choose>
<br/>
</xsl:for-each>
 
</select>
Reply With Quote
  #5  
Old 11-05-2010
Member
 
Join Date: Nov 2009
Posts: 518
Re: Select unique values using xsl

Hello,
The above is correct, still if you need here is an alternative for the above
Code:
<xsl:for-each select="//testcat[not(.=preceding::testcat)]">
                    <xsl:choose>
                        <xsl:when test="$testing = testcat">
                            <option selected="{testcat}"><xsl:value-of select="."/></option>
                        </xsl:when>
                        <xsl:otherwise>
                            <option value="{testcat}"><xsl:value-of select="."/></option>
                        </xsl:otherwise>
                    </xsl:choose>
                    <br/>
                </xsl:for-each>
Reply With Quote
  #6  
Old 14-05-2010
Member
 
Join Date: Nov 2009
Posts: 343
Re: Select unique values using xsl

Hello,
You can even use this
Code:
<xsl:stylesheet version="1.0"
  xmlns:xsl="address here">

  <xsl:output indent="yes" method="txt"/>
  <xsl:key name="vals" match="itms" use="."/>

  <xsl:template match="/">
    <xsl:apply-templates select="/root/itms"/>
  </xsl:template>

  <xsl:template match="itms">
    <xsl:if test="generate-id() = generate-id(key('vals', normalize-space(.)))">
      <xsl:value-of select="."/>
      <xsl:txt>
</xsl:txt>
    </xsl:if>
  </xsl:template>

  <xsl:template match="txt()">
    <xsl:apply-templates/>
  </xsl:template>
</xsl:stylesheet>
Reply With Quote
  #7  
Old 17-05-2010
Member
 
Join Date: Nov 2009
Posts: 359
Re: Select unique values using xsl

Check out this code
Code:
<xsl:output method="xml" />
<xsl:key name="dstscd" match="mktcd" use="."/>
<xsl:key name="dstseg" match="MktSegId" use="."/>
<xsl:template match="/">
<mrkseg>
<xsl:for-each select="//mktcd[generate-id()=generate-id(key('dstscd',.))]">
<mktcd><xsl:value-of select="."/></mktcd>
</xsl:for-each>
<xsl:for-each select="//MktSegId[generate-id()=generate-id(key('dstseg',.))]">
<MktSegId><xsl:value-of select="."/></MktSegId>
</xsl:for-each>
</mrkseg>
</xsl:template>
</xsl:stylesheet>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Select unique values using xsl"
Thread Thread Starter Forum Replies Last Post
Select unique values without using distinct Maya Angelou Software Development 6 17-05-2010 10:26 AM
Select Unique Values (Selecting The Most Recent Record Based On Date) Leeland Software Development 4 14-05-2010 12:16 AM
Select unique records from a table Conraad Software Development 5 13-05-2010 12:01 AM
How to get unique values with respective count from a list hounds Software Development 4 06-03-2010 09:54 PM
SELECT UNIQUE and SELECT DISTINCT TAARIQ Software Development 3 03-06-2009 10:00 PM


All times are GMT +5.5. The time now is 03:31 PM.