472,811 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 software developers and data experts.

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:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/">

<html><head><title>Hello World</title>
<script type="text/javascript" language="JavaScript1.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="????.hello($w)" />

</body></html>

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


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:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/">

<html><head><title>Hello World</title>
<script type="text/javascript" language="JavaScript1.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="????.hello($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.xalan.xslt.Process
Jul 23 '05 #3

"RC" <ra**********@nospam.noaa.gov> wrote in message
news:d2**********@news.nems.noaa.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:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/">

<html><head><title>Hello World</title>
<script type="text/javascript" language="JavaScript1.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="????.hello($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="javascript">
var someVar = hello("<xsl:value-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/xmrefmsxslscriptElement.asp>
Netscape 7 respectively Mozilla has its own built-in XSLT processor but
that doesn't support script in XSLT.
java org.apache.xalan.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(JScript,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="myjavascript: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**********@nospam.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="myjavascript: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.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.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
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...
0
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...
0
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,...
1
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...
3
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...
6
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...
3
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...
1
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> ************************...
0
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.