By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

Firefox, XML, and Javascript (oh my!)

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.