Altova Mailing List Archives


Concise Code!

From: "Adam Knight" <dev@----------.---.-->
To: NULL
Date: 7/20/2005 11:57:00 PM
Hi All,

I am still learning the ropes of xsl. Below i have a stylesheet that works 
fine but is a little long winded.
I would greatly appreciate any input on how to make this stylesheet more 
consice and / or efficient.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.1" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" encoding="ISO-8859-1"/>
  <xsl:param name="subs"/>

  <xsl:template match="/dfile">
    <xsl:if test="$subs">
      <script language="javascript" src="javascript/mm_menu.js"></script>
        <SCRIPT language="javascript">
          function loadMenus() {
            <xsl:call-template name="sub_menus"/>
            writeMenus();
          }
        </SCRIPT>
        <SCRIPT language="JavaScript">loadMenus();</SCRIPT>
    </xsl:if>
    <table height="20" class="home_nav" border="0" cellspacing="0" 
cellpadding="0">
      <tr>
        <td width="40"> </td>
          <xsl:apply-templates select="./df_data_row"/>
      </tr>
    </table>
  </xsl:template>

  <xsl:template name="sub_menus">
    <xsl:for-each select="df_data_row">
      <xsl:if test="child::df_data_row">
        <xsl:call-template name="sub_menus"/>
        window.mnu_<xsl:value-of select="document_id"/> = new 
Menu('<xsl:value-of select="name"/>','Verdana, Arial, 
Helvetica,sans-serif',11,'ffffff','ff3300','000033','000033','left','top',2,2,300,2,1,true,true,true,0);
        <xsl:call-template name="menu_items"/>
    mnu_<xsl:value-of select="document_id"/>.menuWidth = 120
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

<xsl:template name="menu_items">
  <xsl:for-each select="child::df_data_row">
    <xsl:choose>
        <xsl:when test="child::df_data_row">
          mnu_<xsl:value-of
select="parent::df_data_row/document_id"/>.addMenuItem(mnu_<xsl:value-of
select="document_id"/>,"document.location.href='index.php?pg=<xsl:value-of 
select="document_id"/>'");
        </xsl:when>
        <xsl:otherwise>
          mnu_<xsl:value-of
select="parent::df_data_row/document_id"/>.addMenuItem("<xsl:value-of
select="name"/>", "document.location.href='index.php?pg=<xsl:value-of
select="document_id"/>'" );
        </xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
</xsl:template>

<xsl:template match="df_data_row">
   <td>
    <a class="hmlink" href="{$url}?pg={./document_id}">
     <xsl:if test="child::df_data_row and $subs">
      <xsl:attribute name="name">m<xsl:value-of 
select="document_id"/></xsl:attribute>
     <xsl:attribute name="id">m<xsl:value-of 
select="document_id"/></xsl:attribute>
      <xsl:attribute name="onMouseOut">MM_startTimeout();</xsl:attribute>
     <xsl:attribute name="onMouseOver">hideActiveMenus(); 
MM_showMenu(window.mnu_<xsl:value-of 
select="document_id"/>,0,18,null,'m<xsl:value-of 
select="document_id"/>')</xsl:attribute>
     </xsl:if>
    <xsl:value-of select="name"/>
   </a>
  </td>
  <td width="25" align="center" valign="center">
    <xsl:choose>
     <xsl:when test="position() = 1">
      <img src="images/nav_arrow.gif" height="10" width="6"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:if test="position() != last()">
          <img src="images/nav_dots.gif" height="10" width="3"/>
          </xsl:if>
    </xsl:otherwise>
   </xsl:choose>
  </td>
  </xsl:template>
</xsl:stylesheet>

Cheers,
Adam 


Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.