<!-- mlinks.xsl: Copy all elements, but convert multilink elements
     into pop-up menus (1-to-many links) as described at
http://developer.netscape.com/viewsource/smith_menu/smith_menu.html. 

Bob DuCharme 2003  No warrantee expressed or implied. 
 -->

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

  <!-- Assume that input is HTML with a head element. 
       Copy its contents, then add menu scripts. -->
  <xsl:template match="head">
    <xsl:copy>

    <xsl:apply-templates/>

    <script language="JavaScript1.2" 
       src="http://www.snee.com/xml/linking/menu.js">
    </script>

    <script language="JavaScript1.2">
      function onLoad() {

        <!-- For all multilink elements, -->
        <xsl:for-each select="//multilink">
          <xsl:variable name="windowName" select="@id"/>

          <!-- JavaScript (JS) declaration to create window -->
          <xsl:text>window.</xsl:text><xsl:value-of select="$windowName"/>
          <xsl:text> = new Menu();
</xsl:text>

          <!-- For each linkend child of the multilink element that the outer
               for-each is iterating over, output a JS line adding it as a
               choice to the menu, creating a line following this model:

          myMenu.addMenuItem("W3C specs","location='http://www.w3.org/TR'");

          -->

          <xsl:for-each select="linkend">
            <xsl:value-of select="$windowName"/>
            <xsl:text>.addMenuItem("</xsl:text><xsl:value-of select="@title"/>
            <xsl:text>","location='</xsl:text>
            <xsl:value-of select="@URI"/>
            <xsl:text>'");
</xsl:text>
          </xsl:for-each>

          <!-- Don't let the menu be dragged; tweak other parameters. -->
          <xsl:value-of select="$windowName"/><xsl:text>.disableDrag = true;
</xsl:text>
          <xsl:value-of select="$windowName"/><xsl:text>.fontSize = 12;
</xsl:text>
          <xsl:value-of select="$windowName"/><xsl:text>.menuItemHeight = 30;
</xsl:text>
          <xsl:value-of select="$windowName"/><xsl:text>.menuItemIndent = 5;
</xsl:text>
        </xsl:for-each>

          <!-- Following saves all created menus, not just menu @id. -->
          <xsl:value-of select="//multilink[last()]/@id"/>
          <xsl:text>.writeMenus();
</xsl:text>
    }
    // 
    </script>

    </xsl:copy>
  </xsl:template>


  <!-- Tell user about link colors, add compatibility code to end of body. -->
  <xsl:template match="body">
    <xsl:copy>
      <p>(Link color key: <font color="green">columns</font>, 
         <font color="purple">specs</font>, 
         <font color="red">postings</font>, 
         <font color="blue">other</font>)
      </p>
  
      <xsl:apply-templates/>

		<script language="JavaScript1.2">
		  if (document.all || document.getElementById) {
		    onLoad();
		  }
	 	  //
 		</script>

    </xsl:copy>
  </xsl:template>


  <xsl:template match="multilink">
    <!-- Generate an html:a element with a call to the menu. Model:
    <a href="javascript:window.showMenu(window.myMenu)">anchor text</a> -->

    <a href="javascript:window.showMenu(window.{@id})"
       class="{@type}" title="{title}">
      <!-- indicator element of multilink element as anchor text. -->
      <xsl:value-of select="indicator"/> 
    </a>
  </xsl:template>


  <!-- Just copy everything else. -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>


</xsl:stylesheet>
