Docunext

  • About

Javascript versus XSL

April 15th, 2009

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="groupid">     <xsl:for-each select="//getaccountgroups/getaccountgroups">         <option value="{id}">             <xsl:if test="//accountgetbyid/accountgetbyid/groupid=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="groupid">     <xsl:for-each select="//getaccountgroups/getaccountgroups">         <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="//accountgetbyid/accountgetbyid/groupid"/>).attr("selected","selected"); </script>

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

Yearly Indexes: 2010 2003 2005 2006 2007 2008 2009 2004 2011 2012 2013 2015 2019 2020