Saturday, October 01, 2005

Dynamic XSLT


<root>

<Table Caption="Name" Field="Name"/>
<Table Caption="Age" Field="Age"/>
<Table Caption="Roll" Field="RollNo"/>

<row PKID="1" Name="sankar" Age="25" />
<row PKID="2" Name="Dinesh" Age="12" />
<row PKID="3" Name="ramu" Age="35" />
<row PKID="4" Name="ramesh" Age="30" />
<row PKID="5" Name="Ambrish" Age="30"/>

</root>






<xsl:stylesheet
version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<table border="1" width="80%">
<tr>
<xsl:for-each select="//@Caption">
<td><b><xsl:value-of select="."/></b></td>
</xsl:for-each>
</tr>
<xsl:apply-templates select="root/row"/>
</table>
</xsl:template>



<xsl:template match="row">
<xsl:variable name="node" select="."/>
<tr>
<xsl:for-each select="//@Field">
<xsl:variable name="temp" select="."/>
<td>
<xsl:value-of select="$node/@*[name()=$temp]/."/>
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>

No comments: