[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problem Using JavaScript with XSLT

Subject: RE: [xsl] Problem Using JavaScript with XSLT
From: "Jacoby, Peter R." <PJACOBY@xxxxxxxxxxxx>
Date: Thu, 25 Jul 2002 15:28:39 -0400
problems using javascript
>What am I doing wrong?

You are confusing the relationship between XSLT and JavaScript.  What you
say you want to do is pass some code down to execute on the client, but your
stylesheet is set up to execute the code on the server as an extension
function.

If you want to execute the JavaScript on the client, simply create a
<script> element (with a type attribute as the lang or language attribute
has been deprecated) and put any code you want in it.  

Here is an example that will get you started (you may need to copy some of
your namespace declarations, but they are not necessary to get the
JavaScript to work):

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="yes"/>

<xsl:template match="/">


<html>
	<head>
		<title>"Errors"</title>
		<script type="text/javascript">
			function toggle() {
				alert("Hi");
			}
		</script>
	</head>
	<body>
		<a href="#" onclick="toggle()"> 
			<xsl:text>hi</xsl:text>
		</a>
	</body>
</html>
</xsl:template>
</xsl:stylesheet>

Hope that helps.

-Peter 


-----Original Message-----
From: Kuhns Matt [mailto:kuhns_m@xxxxxxxxx]
Sent: Thursday, July 25, 2002 2:46 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Problem Using Javascript with XSLT


I am having a problem putting a javascript function in
a XSLT.
Here is my XSLT, I simplified it for this example:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lxslt="http://xml.apache.org/xslt"
xmlns:totalSys="TotalSystem"
extension-element-prefixes="totalSys">
<xslutput method="html" encoding="utf-8"
indent="yes"/>

<lxslt:component prefix="totalSys" functions="toggle">
<lxslt:script lang="javascript">

function toggle() {
alert("hi");
} 

</lxslt:script>
</lxslt:component>

<html>
<head>
<title>"Errors"</title>
</head>
<body>
<a href="#" onclick="totalSys:toggle()"> 
<xsl:text>hi</xsl:text>
</a>
</body>
</html>

When my sheet is generated, I click on my link and I
get an error from my browser it says that an Object is
expected.
What am I doing wrong?
Thanks in advance

__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.