Jump to content

XSL Variables


lscottcline

Recommended Posts

I am trying to allow a user to click on an item and the item pop up in a dialog box using JavaScript. Here is my xsl code:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">	<xsl:template match="/">	<HTML>	<HEAD>	<script LANGUAGE="javascript">	</SCRIPT>	</HEAD>	<BODY>	<TABLE border="0" cellpadding="3" cellspacing="3">  <TR>  	<TH style="background-color:beige">Name</TH>  	<TH style="background-color:beige">Salary</TH>  	<TH style="background-color:beige">Dept.</TH>  </TR>	<xsl:for-each select="employees/employee" order-by="name">  <xsl:variable name="Dept" select="department" />  <TR VALIGN="top"   	onmouseover="this.style.backgroundColor='lightcyan'"   	onmouseout="this.style.backgroundColor='white'"   	style="background-color:white;cursor:hand" onclick="alert('You are in the '{Dept}' Department!)">  	<TD>    <xsl:value-of select="name"/>  	</TD>  	<TD>    <xsl:value-of select="salary"/>  	</TD>  	<TD>    <xsl:value-of select="department"/>  	</TD>  </TR>	</xsl:for-each>	</TABLE>	</BODY>	</HTML>	</xsl:template></xsl:stylesheet>

Here is the XML code that is connecting to it:

<?xml version="1.0" ?><?xml-stylesheet type="text/xsl" href="employees18.xsl"?><employees>	<employee id="123">  <name>Roberts</name>  <salary payperiod="weekly">23500</salary>  <department>Development  	<title>Developer</title>  </department>	</employee>	<employee id="124">  <name>Freestone</name>  <salary payperiod="weekly">51000</salary>  <department>Human Resources  	<title>Recruiter</title>  </department>	</employee></employees>

When I run this file I get the following error, rather I delete the namespace (xmlns:xsl="http://www.w3.org/TR/WD-xsl") or leave it.Keyword xsl:variable may not be used in namespace http://www.w3.org/TR/WD-xsl. Any help would be greatly appreciated.Thanks,Scott

Link to comment
Share on other sites

  • 2 weeks later...

Try using this namespace:

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

Also, when you select the variable, I think there must be a $ right after the {. Like:

'You are in the '{$Dept}' Department!)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...