You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Heather Lindsay <he...@Trifolium.com> on 2000/06/12 15:40:21 UTC

confused about extensions (Javascript)

hi,
	After reading all of the documentation on extensions that I could
find (in xalan dist. and in Mike Kay's XSLT book), I am still confused on
how to use extensions.  I am trying to figure out how to get Javascript to
work in XSLT so I am trying to do the following:

I what to output something which will produce the same as this html file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> Background Color Pr17 </TITLE>
<SCRIPT language="JavaScript">
var user= prompt("Please enter your name:","");
function pick_color(color)
{
	alert("Hello "+user+", you chose "+color+".")
	document.bgColor=color
}
</SCRIPT>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
<form>
<center>
Please select a color for this background of this page.<br>
<input type=button value=Red onClick="pick_color('red')">
<input type=button value=Blue onClick="pick_color('blue')">
<input type=button value=Green onClick="pick_color('green')">
<input type=button value=White onClick="pick_color('FFFFFF')">
<input type=button value=Pink onClick="pick_color('pink')">
</form>
</center>
</BODY>
</HTML>

Without actually using anything from my XML file, I am trying to do the same
as above in XSLT.  Here is my XSL file:
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"   
    xmlns:lxslt="http://xml.apache.org/xslt"
    xmlns:my-ext="ext1"
    extension-element-prefixes="my-ext">

<lxslt:component prefix="my-ext" elements="init" functions="pick_color">
	<lxslt:script lang="javascript">
		var user= prompt("Please enter your name:","");
		function init (xslproc, elem)
		{
			user=elem.getAttribute("user"));
			return null;
		}
		function pick_color(color)
		{
			alert("Hello "+user+", you chose "+color+".")
			document.bgColor=color
		}
	</lxslt:script>
  </lxslt:component>

	<xsl:template match="/">
		<HTML>
		   <HEAD>
			<TITLE> Background Color Pr17 </TITLE>
		   </HEAD>

		   <BODY BGCOLOR="#FFFFFF">
		      <form>
		      <center>
				Please select a color for this background of
this page.<br/>
				<input type="button" value="Red"
onClick="my-ext:pick_color('red')"/>
				<input type="button" value="Blue"
onClick="my-ext:pick_color('blue')"/>
				<input type="button" value="Green"
onClick="my-ext:pick_color('green')"/>
				<input type="button" value="White"
onClick="my-ext:pick_color('FFFFFF')"/>
				<input type="button" value="Pink"
onClick="my_ext:pick_color('pink')"/>
		      </center>
		      </form>
		   </BODY>
		</HTML>
	</xsl:template>
</xsl:stylesheet>

I know that I'm doing something very wrong.  I can output html with the
above XSL but clicking on the buttons on the page does nothing.  I can see
why the above does not work but I can't see how to produce my desired
result.  Would someone please help?

Thanks so much,
Heather