You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Mike Gargiullo <mg...@smallworld.com> on 2000/06/12 15:53:02 UTC

RE: confused about extensions (JavaScript)

<script language="JavaScript" src="../js_libraries/drop_down.js"
type="text/javascript"></script>
 
import your JavaScript into the XSL using the line above.  Just don't
include the script tags when writing the scripts though.  You might have to
configure Apache to serve the .js extension though.  This works great for
us.  You can call functions from the xsl using onClicks and Mouseovers.

-----Original Message-----
From: Heather Lindsay [mailto:heather.lindsay@Trifolium.com]
Sent: Monday, June 12, 2000 9:40 AM
To: 'xalan-dev@xml.apache.org'
Subject: 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