Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

add attribute to HTML Tag Based on Cond Using XSLT

Hi Guys,

I'm having one probelm, i need to add an id attribute based on condition using XSLT.

Here my code, Its working, but i need to optimize. Can any one help me out?
(i.e) <li id="current"> based on conditon

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="SelMenu">Client</xsl:param>
<xsl:output method="html"/>
<xsl:template match="/">
<div id="Tabs">
<ul>
<xsl:for-each select="Menus/Menu">
<xsl:if test="MenuID=$SelMenu">
<li id="current">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="URL"/>
</xsl:attribute>
<span>
<xsl:value-of select="MenuText"/>
</span>
</xsl:element>
</li>
</xsl:if>
<xsl:if test="MenuID!=$SelMenu">
<li >
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="URL"/>
</xsl:attribute>
<span>
<xsl:value-of select="MenuText"/>
</span>
</xsl:element>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</div>
</xsl:template>
</xsl:stylesheet>

Thanks & Regards
RamesH
[1843 byte] By [Ramesh Kumar] at [2007-11-11 8:37:32]
# 1 Re: add attribute to HTML Tag Based on Cond Using XSLT
Ya, no one is answered for my post. Finally i got a solution using
<xsl:when> i've optimized the code................
Ramesh Kumar at 2007-11-11 23:28:32 >