Results 1 to 7 of 7

Thread: Select unique values using xsl

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

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

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

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

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

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

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

Similar Threads

  1. Select unique values without using distinct
    By Maya Angelou in forum Software Development
    Replies: 6
    Last Post: 17-05-2010, 10:26 AM
  2. Replies: 4
    Last Post: 14-05-2010, 12:16 AM
  3. Select unique records from a table
    By Conraad in forum Software Development
    Replies: 5
    Last Post: 13-05-2010, 12:01 AM
  4. How to get unique values with respective count from a list
    By hounds in forum Software Development
    Replies: 4
    Last Post: 06-03-2010, 09:54 PM
  5. SELECT UNIQUE and SELECT DISTINCT
    By TAARIQ in forum Software Development
    Replies: 3
    Last Post: 03-06-2009, 10:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,129,551.46718 seconds with 17 queries