Tuesday, December 21, 2010

Distinct in XSLT

This Example Use for sort the year in xslt for this we need to get unique year id i.e. in xslt generic-id bases we can trace unique here example below:----

Test XML Feed Here:--
<state id="26179" status="Approved" golive="Wednesday, December 22, 2010" created="Wednesday, December 22, 2010" golivetime="9:00:00 AM" createdtime="9:42:11 AM" creator="Indigo Consulting">
<elements state="26179" parent="0">
<element id="97398" position="1" type="Custom">
<content>
<day>6</day>
<month>February</month>
<year>1996</year>
<title>testing first new2</title>
<historyimage />
</content>
</element>
<element id="97399" position="1" type="Custom">
<content>
<day>4</day>
<month>February</month>
<year>1996</year>
<title>testing first similar new2</title>
<historyimage />
</content>
</element>
<element id="97403" position="1" type="Custom">
<content>
<day>4</day>
<month>October</month>
<year>2012</year>
<title>testing first new5</title>
<historyimage />
</content>
</element>
</elements>
</state>

XSL Content:-
-----------
<xsl:key name="distinctYear" match="state/elements/element[@type = 'Custom']/content" use="./year"></xsl:key>

---Under Applytemplate section--------------
<xsl:for-each select="state/elements/element[@type='Custom']/content[generate-id(key('distinctYear', ./year)) = generate-id()]">
<xsl:sort select="year"/>
<li>
<a href="#{year}">
<xsl:value-of select="year" />
</a>
</li>
</xsl:for-each>

No comments:

Post a Comment