473,856 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hwo to do Hello World From XSLT to JavaScript?

RC
Hello World,
I am try do call a JavaScript function from XSLT, but I got
function not avaible error. See "????" below.
Would someone out there tell me how?
Thank Q!

<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/">

<html><head><ti tle>Hello World</title>
<script type="text/javascript" language="JavaS cript1.2">

function hello(w) {
return ("Hello " + w + "!");
}
//
</script>
</head><body>

<xsl:variable name="w" select='World' />

<!-- How do I call JavaScript function here? -->
<xsl:value-of select="????.he llo($w)" />

</body></html>

</xsl:template>
</xsl:stylesheet>
Jul 23 '05 #1
6 4698


RC wrote:

I am try do call a JavaScript function from XSLT, but I got
function not avaible error.
I think you confuse two techniques, one is to use script functions in an
XSLT stylesheet, the other is to use script functions in an HTML document.
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/">

<html><head><ti tle>Hello World</title>
<script type="text/javascript" language="JavaS cript1.2">

function hello(w) {
return ("Hello " + w + "!");
}
//
</script>
So here you have a literal result element <script> in your stylesheet
meaning that <script> element and the function it defines are part of
the HTML document which is the result of the XSLT transformation.
</head><body>

<xsl:variable name="w" select='World' />

<!-- How do I call JavaScript function here? -->
<xsl:value-of select="????.he llo($w)" />


Here you have an XPath expression that tries to call a function defined
in script, for that to work the XSLT processor needs to support
extension functions written in script and you need to use the proper way
for the XSLT procesor of your choice to include the function.

Which XSLT processor are you using?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
RC
Martin Honnen wrote:
Which XSLT processor are you using?


Netscape 7.2.x and/or IE 6.x
Or

java org.apache.xala n.xslt.Process
Jul 23 '05 #3

"RC" <ra**********@n ospam.noaa.gov> wrote in message
news:d2******** **@news.nems.no aa.gov...
Hello World,
I am try do call a JavaScript function from XSLT, but I got
function not avaible error. See "????" below.
Would someone out there tell me how?
Thank Q!

<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/">

<html><head><ti tle>Hello World</title>
<script type="text/javascript" language="JavaS cript1.2">

function hello(w) {
return ("Hello " + w + "!");
}
//
</script>
</head><body>

<xsl:variable name="w" select='World' />

<!-- How do I call JavaScript function here? -->
<xsl:value-of select="????.he llo($w)" />

</body></html>

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


If you want the *browser* to execute this javascript, based on a
variable-value, do this:

<xsl:variable name="w" select='World' />
....
....
<script language="javas cript">
var someVar = hello("<xsl:val ue-of select="$w"/>");
...
...
</script>
....

If you want to execute javascript *from within the XSLT* transformation
itself, you have to use XSLT-extensions for JavaScript.
Go to this site for more info:
http://xml.apache.org/xalan-j/extensions.html
Good luck.
Jul 23 '05 #4


RC wrote:
Martin Honnen wrote:
Which XSLT processor are you using?

Netscape 7.2.x and/or IE 6.x


IE uses MSXML 3 by default, MSXML 3 has support for script in XSLT, see
<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/xmlsdk/html/xmrefmsxslscrip tElement.asp>
Netscape 7 respectively Mozilla has its own built-in XSLT processor but
that doesn't support script in XSLT.
java org.apache.xala n.xslt.Process


I am not sure about Xalan but if it has support for JavaScript then most
certainly not in a portable way to MSXML.

As a summary, try to avoid script in your XSLT stylesheet solutions, it
is not portable at all, even if the vendor is the same, for instance
while both MSXML and MS .NET support scripting in XSLT the APIs exposed
to script differ.

Try to ask yourself why you think you need script in an XSLT stylesheet
and then try to find ways to solve the problem with standard XSLT and
XPath 1.0.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #5
RC
Martin Honnen wrote:

I am not sure about Xalan but if it has support for JavaScript then most
certainly not in a portable way to MSXML.
You may want to see this link below. It introduce about
Bean Scripting Framework (BSF), which support
JavaScript, JPython, Jacl, ActiveScript(JS cript,VBScript) ,
PerlScript, etc.

http://xml.apache.org/xalan-j/extensions.html

Also see

http://xml.apache.org/xalan-j/extensionslib.html
Try to ask yourself why you think you need script in an XSLT stylesheet
and then try to find ways to solve the problem with standard XSLT and
XPath 1.0.


Hahaha....!
I am try to do something like

2005-02-28 23:45:00 + 30 = 2005-03-01 00:15:00

I need to take care the leap year for February 28 days or 29 days,
the months for 30 days or 31 days.

I can do this in XSLT, but will very hassle and long.
Will be nice for me call Perl, or Java or JavaScript?

like
<xsl:value-of select="myJavaS cript:addTime(' 2005-02-28 23:45:00', 30)" />
Jul 23 '05 #6
JRS: In article <42************ **@nospam.noaa. gov>, dated Wed, 30 Mar
2005 07:31:12, seen in news:comp.lang. javascript, RC
<ra**********@n ospam.noaa.gov> posted :
Hahaha....!
I am try to do something like

2005-02-28 23:45:00 + 30 = 2005-03-01 00:15:00

I need to take care the leap year for February 28 days or 29 days,
the months for 30 days or 31 days.

I can do this in XSLT, but will very hassle and long.
Will be nice for me call Perl, or Java or JavaScript?

like
<xsl:value-of select="myJavaS cript:addTime(' 2005-02-28 23:45:00', 30)" />

You need to decide whether you want to do it in UTC or in local time.
Assuming from your -0500 that you are in East CONUS, it's likely that
you won't have to wait more than about 36 hours from now to see the
difference!

S = "2005-02-28 23:45:00" // or that plus " GMT"
S = S.replace(/-/g, "/") // AFAIK, all setups take yyyy/mm/dd
D = new Date(S)
D.setMinutes(D. getMinutes()+30 ) // or ...etUTCMin...

That will be correct for as long, ahead or aback, as the calendar rules
of the interpreting system are valid.

You'll also want, it seems, code to output D in ISO 8601, UTC or local;
for that, etc., see my Web site via sig below.

You should, of course, have known that from reading the newsgroup FAQ.
Now, after reading my relevant pages, can you explain US non-Fed
standards for week numbering?!? And US IRS practice?

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2714
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron extension responsible for the xslt functions. The problem i have is that the obtained transformation is not the waited one. I try to proccess the same XML file with XSL file with a program called XMLspy and i obtained the desire and waited...
0
1321
by: RC | last post by:
Hello World, I am try do call a JavaScript function from XSLT, but I got function not avaible error. See "????" below. Would someone out there tell me how? Thank Q! <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" /> <xsl:template match="/">
0
2361
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag, such as a div with a runat=server. I can somewhat do this if I create a server control and include the control within the html div tag but this method (borrowed from ASP.NET Website Programming by Wrox press thanks guys) does not give me the full...
1
1643
by: John Moore | last post by:
I have a set of code that is called on every page load that loads an xslt file. The xslt file has an embedded <script> tag. Loading the page mutliple times causes aspnet_wp.exe to use all available memory and then reset. As this happens several times over the course of an 8 hour stress run, I'm looking for a solution. The xslt file has the following: <xsl:if test="$strPageCaller=''"> <SCRIPT LANGUAGE="JavaScript">BPB()</SCRIPT>...
3
6073
by: salvadorvp | last post by:
Hi, here I have a very simple 'hello world' example that makes use of Yahoo! User Interface Library. I have a problem with my response string coming back as ''. I managed to check that everything else works. The requested 'SayHello.html' file only contains the string "hello, world". Here is my code:
6
2660
by: Pete Verdon | last post by:
Summary: Can I do an XSLT transform, in the client, of a tree of nodes taken from the displayed page DOM in IE? This works in Firefox. Hi, I'm just starting the process of rewriting part of a "database frontend" type of intranet application. The existing table-display code consists of a mountain of very clever but extremely brittle spaghetti-javascript, which I'm planning to replace with XSLT transformations. At present I'm still...
3
1690
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have dealing with XML file tags used DOM. var options = xmlDocument.getElementsByTagNameNS(null,"myXMLTag"); doMyFunctionWithHTMLDOM(options);
1
1233
by: Toxician | last post by:
why can i use javascrtip to output the file below into html and also able to use xslt to do the same thing ??? xml.xml <root> <node>This is a node </node> <root> ************************ xml.js
0
2583
by: tosreejithp | last post by:
Hi, My first problem was i am not able to compiled a file from java script to java class.Now its clear and working fine..now i can convert a java script file to java class by Rhino Java Script Compiler.But now i am facing 1 more problem.i want to run that java class in IntelliJIdea.but its runnig with no error and not getting the out put.This is the converted java class for printing "HelloWorld". import org.mozilla.javascript.*; import...
0
9920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11063
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10699
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10790
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9535
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7098
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5762
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4580
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.