One thing I don’t like about XSL is the complexity of some simple tasks, so I’m thinking of ways to use Javascript instead.

For example this dropdown list is pretty complicated, just to make sure that the currently selected option is active:

<select name=”group_id”>     <xsl:for-each select=”//get_account_groups/get_account_groups”>         <option value=”{id}”>             <xsl:if test=”//account_get_by_id/account_get_by_id/group_id=id”>                 <xsl:attribute name=”selected”>selected</xsl:attribute>             </xsl:if>             <xsl:value-of select=”name”/>         </option>     </xsl:for-each> </select>

I bet that I can make it simpler with Javascript.Yes, indeed!

<select name=”group_id”>     <xsl:for-each select=”//get_account_groups/get_account_groups”>         <option value=”{id}” id=”g_{id}”>             <xsl:value-of select=”name”/>         </option>     </xsl:for-each> </select>

<script type=”text/javascript”>   $(“#g_”+<xsl:value-of select=”//account_get_by_id/account_get_by_id/group_id”/>).attr(“selected”,”selected”); </script>

FYI, this code is from PBooks, and the solution I’ve proposed uses my favorite Javascript library: jQuery.