473,396 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Firefox, XML, and Javascript (oh my!)

AOO
(Reposted from mozilla.support.firefox)

Hello experts!

I've recently run into a problem regarding the use xml+xslt+javascript
in Firefox. The problem is that I'm loading an XML document with a
XSLT stylesheet
that has embedded javascript. I use the javascript for formatting
date-
times (see http://blog.stevenlevithan.com/archi...te-format-1-0).

The date.format.js library is included in the 'head' section of the
document. I also create a function to transform a unix timestamp
string (from the xml) into something human readable. So the top of my
stylesheet looks as follows:

<xsl:template match='/'>
<html>
<head>
<script type='text/javascript' src='/ui/date.format.js'></script>
<script type='text/javascript'>
function unix2human(unix) {
var date = new Date(unix * 1000);
return dateFormat(date, 'dddd, mmmm d, yyyy');
}
</script>
</head>

.....

And here is the section where unix2human is called:

<a href='somelink'>
<script>
document.write(unix2human(<xsl:value-of select='normalize-space(.)'/
>));
</script>
</a>

Examining the error console I find that that unix2human is not defined
(but it is!). Doubly frustrating is that this code works as intended
in Safari --- i.e. the dates are converted from a unix timestamp to
the correct format. Any thoughts?

Anton
Jul 7 '08 #1
4 2639
AOO wrote:
<script>
document.write(unix2human(<xsl:value-of select='normalize-space(.)'/
>));
</script>
</a>

Examining the error console I find that that unix2human is not defined
(but it is!).
Can you post a URL where we can see the problem?

But generally you should not that using document.write in the result of
an XSLT transformation is not supported in Firefox, see
http://developer.mozilla.org/en/docs...ument.write.3F
so your approach above does not work with Firefox. That however does not
explain why you get an error that the function is not defined.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 7 '08 #2
AOO
On Jul 7, 6:10*am, Martin Honnen <mahotr...@yahoo.dewrote:
AOO wrote:
<script>
* *document.write(unix2human(<xsl:value-of select='normalize-space(.)'/
));
</script>
</a>
Examining the error console I find that that unix2human is not defined
(but it is!).

Can you post a URL where we can see the problem?

But generally you should not that using document.write in the result of
an XSLT transformation is not supported in Firefox, seehttp://developer.mozilla.org/en/docs/XSL_Transformations_in_Mozilla_F...
so your approach above does not work with Firefox. That however does not
explain why you get an error that the function is not defined.

--

* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
Hi Martin,

Gah. That's nice to know... So I guess a possible workaround would be
to load the page with the ugly timestamp in a span, extract the
timestamp and replace the content of the span with a snazzy formatted
date.

As for the url try http://nobby.shacknet.nu:42000/search?tag=9000,
though not sure how useful this will be, if you take a look at the
source you will know what I mean. Note that the server may not be up
all the time...

Anton
Jul 7 '08 #3
AOO
On Jul 7, 6:10*am, Martin Honnen <mahotr...@yahoo.dewrote:
AOO wrote:
<script>
* *document.write(unix2human(<xsl:value-of select='normalize-space(.)'/
));
</script>
</a>
Examining the error console I find that that unix2human is not defined
(but it is!).

Can you post a URL where we can see the problem?

But generally you should not that using document.write in the result of
an XSLT transformation is not supported in Firefox, seehttp://developer.mozilla.org/en/docs/XSL_Transformations_in_Mozilla_F...
so your approach above does not work with Firefox. That however does not
explain why you get an error that the function is not defined.

--

* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
Hi Martin,

(I'm pretty sure I posted this before but Google Groups seems to have
eaten it...)

So, that's good to know... I guess a workaround would be to wrap the
timestamp in a span element, use javascript to extract and format the
time, and replace the contents of the span.

As for a url, you can try http://nobby.shacknet.nu:42000/search?tag=art.
Although I'm not sure how helpful this will be, especially since view
source will just give you the straight XML.

Anton
Jul 7 '08 #4
AOO wrote:
Gah. That's nice to know... So I guess a possible workaround would be
to load the page with the ugly timestamp in a span, extract the
timestamp and replace the content of the span with a snazzy formatted
date.
It should suffice to put the span with an id attribute in the HTML
generated by the XSLT stylesheet, then your JavaScript can format the
timestamp and put the result into the string using

document.getElementById('spanId').appendChild(docu ment.createTextNode(unix2human(<xsl:value-of
select='normalize-space(.)'/>)));
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 8 '08 #5

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

Similar topics

4
by: Guillaume CABANAC | last post by:
Hi everybody, Does anybody know how to access a remote database (say Oracle) from JavaScript code (within a Firefox Extension) ? I know ADO via ActiveX in the IE world and think a similar...
2
by: Roger | last post by:
Anyone have any links for a good tutorial on the FireFox Javascript Console? In particular, I am looking for information on the capabilities of the Evaluate box. (1) I can put multiple statements...
3
by: Jon Natwick | last post by:
This "Countdown Timer" code works fine with Ie, but I receive an "Error: Form1 is not defined" error with Firefox 1.0.0 and 1.0.1. <body MS_POSITIONING="FlowLayout" onload="InitializeTimer()">...
5
by: Roger Withnell | last post by:
This is a framed webpage with the navigation bar in "NavBar" and the main window in "Main". When opening a new page in "Main" from "NavBar" with: function OpenFrameWindow(src) { var...
3
by: google | last post by:
I am trying to complete a javascript application and am having problems with code similar to that show below. Much testing has shown that Firefox finishes the code shown in around 0.25 secs but...
2
by: Altman | last post by:
I have created an ascx control and I am calling registerclientscriptblock. The path to the js file is relative to the aspx page and not the ascx file. The function runs fine in IE7 but in...
5
by: cbs7 | last post by:
Hi all I'm a complete newbie to web development and Javascript especially. I've been creating a form for a webpage and have used a validation script gen_validatorv2.js which I downloaded from the...
4
by: iamaporkaholic | last post by:
The main page of the site has this script which determines the language settings of the OS. This works fine for IE but not for firefox. Is there any other codes which i have to insert to make sure...
5
by: johnric | last post by:
I can't seem to get firefox to read the image size in my javascript. It will work in IE and firefox but firefox will not read the image size. Can anyone see the problem in my code? I am new to...
1
by: craigw147 | last post by:
I have a problem with the global variable valueValidated when I try the following code in firefox. I wish to validate a value when either the user leaves the field by using the tab key or if they...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.