Thursday, October 21, 2010

Sort values in XSL

Distinct Year

<xsl:key name="distinctYear" match="state/elements/element[@type='Custom']/content" use="substring(date,7,10)"></xsl:key>

I have used three attributes here i.e.
1. name :- this is a key name which will use further.
2. match :- this is the route of content data
3. use :- this is attrubute value / name which we want to sort

<select id="ddYear" name="ddYear" onchange="javascript:fnOnchange()">
<xsl:for-each select="state/elements/element[@type='Custom']/content[generate-id() = generate-id(key('distinctYear', substring(date,7,10)))]">
<xsl:sort select="substring(date,7,10)" data-type="number" order="ascending" />
<option>
<xsl:value-of select="substring(date,7,10)"/>
</option>
</xsl:for-each>
</select>

here i used for-each loop to find all elements with distinct values

ex:-
generate-id() :- The generate-id() function returns a string value that uniquely identifies a specified node.
key(Param1,Param2) :- Param1 :- this is key name which assigned
Param2 :- this is the string value which want to be destinected

No comments:

Post a Comment