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