We help IT Professionals succeed at work.
Get Started

XSLT menu

375 Views
Last Modified: 2013-11-19
Hi again!

I have an xml file for a menu (below):

<Menu>
<Title>Catalog</Title>
<MenuItems>
<CDs>
<Subitem>Albums</Subitem>
<Subitem>Singles</Subitem>
<SubItem>Compilations</SubItem>
<SubItem>Soundtracks</SubItem>
</CDs>
<DVDs>
<SubItem>DVDMovie</SubItem>
<SubItem>DVDGame</SubItem>
<SubItem>MusicDVD</SubItem>
<SubItem>DVDTV</SubItem>
</DVDs>
</MenuItems>
</Menu>

Then i have this xslt file with a javascript for a dropdown menu (below):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
   

<xsl:template match="MenuItems/*">

<xsl:variable name="NodeName">
<xsl:value-of select="name(current())"/>
</xsl:variable>
<html>
<head>
<script lang="javascript" type="text/javascript" >
 function HideShowDiv(divid)
 {
      var divlayer = document.getElementById(divid);
      if(divlayer.style.display == "block")
      {
      divlayer.style.display = "none";
      }
      else
      divlayer.style.display = "block"
 }
  function ChangeBg(tdid)
  {
  var td = document.getElementById(tdid);
  td.style.background = "#3399ff";
  td.style.color= "white";
  }
  function ReturnBg(tdid)
  {
  var td = document.getElementById(tdid);
  td.style.background = "white";
  td.style.color = "black";
  }
  </script>
</head>
<body>
<h1><xsl:value-of select="Menu/Title"/></h1>
<div>
<table border="1" width="150px" >
<tr>
<td onmousedown="HideShowDiv('{$NodeName}')" align="Center"><xsl:value-of select="$NodeName"/></td>
</tr>
</table>
<div style="OVERFLOW:AUTO; width=150px;height=100px; display:none" runat="server" id="{$NodeName}" >
<xsl:for-each select="node()">
<table>
<xsl:variable name="ChildNodeName">
<xsl:value-of select="./child::node()"/>
</xsl:variable>
<td onmouseover="ChangeBg('{$ChildNodeName}')"
 id="{$ChildNodeName}" onmouseleave="ReturnBg('{$ChildNodeName}')"
 width="150px" align="center"><xsl:value-of select="$ChildNodeName"/></td>
</table>
</xsl:for-each>
</div>
</div>
</body>
</html>

</xsl:template>
</xsl:stylesheet>

I have a set of html files such as ALBUMS.html, SINGLES.html and i need to have hyperlinks from a subitem in the xml file such as <SubItem>Albums</SubItem> to a html file such as ALBUMS.html and so on for each individual sub item.
I've looked at xlink but can't get it to work.  Can anybody help me with this?
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE