Friday, November 04, 2005

XSL Key


you can segregate distinct values using xsl:key from XML



<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="Brand-Id" match="//row" use="@BrandId"/>

<xsl:template match="/">
<table cellpadding="4" Id="xsltable" width="70%" align="center">
<tr class="tablecontent2">
<td>
<xsl:apply-templates
select="/Root/row[generate-id()=generate-id(key('Brand-Id',@BrandId)[1])]"
mode="Brand"/>
</td>
</tr>
</table>
</xsl:template>


<xsl:template match="row" mode="Brand">
<xsl:variable name="brandid" select="@BrandId"/>
<xsl:value-of select="/Root/row[@BrandId=$brandid]/@BrandName"/>

</xsl:stylesheet>

No comments: