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

XML, CSS and JavaScript

P: n/a
I'm trying to apply CSS to an XML file and interject a JavaScript
function into the page. I have the following source code:

foo.xml
======
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="foo.css" type="text/css"?>

<doc>
<element1>
my text
</element1>
</doc>
foo.css
======
element1 {
display: block;
height: 100px;
border: 1px solid Black;
This works great for me when I load that page in IE and Firefox. Now, I
want to add a JavaScript file into the mix.

foo.js
=====
alert( "Hello, World from foo.js");
When I try to include it into the XML as a <scripttag, I don't get
the desired behavior. I've seen suggestions where people are using XSLT
to transform the XML into HTML, but I'd prefer to leave HTML and all
it's legacy behind. Is this possible?

Jul 19 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a


Dan H wrote:

When I try to include it into the XML as a <scripttag, I don't get
the desired behavior. I've seen suggestions where people are using XSLT
to transform the XML into HTML, but I'd prefer to leave HTML and all
it's legacy behind. Is this possible?
If you want to go esoteric to build pages that work with some latest
releases of some browser then you can use the XHTML script element in
XML e.g.
<script xmlns="http://www.w3.org/1999/xhtml" type="text/javascript"
src="foo.js"></script>
Mozilla and Opera should support that only you need to learn to script
the XML DOM then (no document.write) and live with browser flaws like
Mozilla not incrementally parsing and rendering XML so expecting script
to do anything while the document is parsed can be a pain.
And IE knowns nothing about elements in the XHTML namespace, it will not
understand that script element as having any particular semantics.

So go ahead, leave that "legacy HTML" behind you, and lots of potential
visitors too.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 19 '06 #2

P: n/a
Someone's a little grumpy. Instead of writing responses maybe you
should try a nap. Or maybe it's that "warm" German personality you
have.

While some seek to look at the practical applications for everything,
some of us experiment with the "esoteric" to see what it's capable of.

Martin Honnen wrote:
Dan H wrote:

When I try to include it into the XML as a <scripttag, I don't get
the desired behavior. I've seen suggestions where people are using XSLT
to transform the XML into HTML, but I'd prefer to leave HTML and all
it's legacy behind. Is this possible?

If you want to go esoteric to build pages that work with some latest
releases of some browser then you can use the XHTML script element in
XML e.g.
<script xmlns="http://www.w3.org/1999/xhtml" type="text/javascript"
src="foo.js"></script>
Mozilla and Opera should support that only you need to learn to script
the XML DOM then (no document.write) and live with browser flaws like
Mozilla not incrementally parsing and rendering XML so expecting script
to do anything while the document is parsed can be a pain.
And IE knowns nothing about elements in the XHTML namespace, it will not
understand that script element as having any particular semantics.

So go ahead, leave that "legacy HTML" behind you, and lots of potential
visitors too.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 19 '06 #3

P: n/a
Dan H said the following on 7/19/2006 3:53 PM:
Someone's a little grumpy. Instead of writing responses maybe you
should try a nap. Or maybe it's that "warm" German personality you
have.
Or maybe it's your ignorance of a good answer that eludes you.
While some seek to look at the practical applications for everything,
some of us experiment with the "esoteric" to see what it's capable of.
Then experiment. But say so to begin with and you will see a difference
in the response. The basic assumption in this group is that it is for
the WWW and the responses will be based on that unless you say differently.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 19 '06 #4

P: n/a

Randy Webb wrote:
Dan H said the following on 7/19/2006 3:53 PM:
Someone's a little grumpy. Instead of writing responses maybe you
should try a nap. Or maybe it's that "warm" German personality you
have.

Or maybe it's your ignorance of a good answer that eludes you.
While part of the message was good (i.e. <script
xmlns="http://www.w3.org/1999/xhtml" type="text/javascript"
src="foo.js"></script) there's no reason to flame someone asking a
legit question in a newsgroup. It's not as if I was asking a common
question.
While some seek to look at the practical applications for everything,
some of us experiment with the "esoteric" to see what it's capable of.

Then experiment. But say so to begin with and you will see a difference
in the response. The basic assumption in this group is that it is for
the WWW and the responses will be based on that unless you say differently.
So what. He could have said it would be a hit or miss proposition with
different browsers without such inflammatory language. Do all
non-production issues get shot down with such force or is the point to
banish the non JavaScript experts?

Jul 19 '06 #5

P: n/a


Dan H wrote:

While some seek to look at the practical applications for everything,
some of us experiment with the "esoteric" to see what it's capable of.
Go ahead and experiment, but if the aim is not experimenting but rather
leaving "legacy HTML" behind then I think you will find that HTML is not
legacy and HTML and CSS and JavaScript has much better support and
implementation than XML and CSS and JavaScript.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '06 #6

P: n/a
VK

Dan H wrote:
I'm trying to apply CSS to an XML file and interject a JavaScript
function into the page.

It is not possible.
XML is /data source/. It is not a viewable document: it is a source to
generate viewable document. You can generate HTML out of it, XHTML,
Excel sheet etc. etc. But you cannot handle the presentational
attributes of a data source as you cannot talk about "of what color
bytes are" :-)

Note: All modern browsers have XML Viewer in them to look at XML data
with more comfort. But it is not about "document presentation" or
styling or scripting of any kind of course.

I have the following source code:

foo.xml
======
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="foo.css" type="text/css"?>

<doc>
<element1>
my text
</element1>
</doc>
foo.css
======
element1 {
display: block;
height: 100px;
border: 1px solid Black;

You would be highly surprised of what kind of document really is
generated inside your browser :-). A hint: nothing about XML. The rest
depends on Content-Type you are using for foo.xml
When I try to include it into the XML as a <scripttag, I don't get
the desired behavior. I've seen suggestions where people are using XSLT
to transform the XML into HTML, but I'd prefer to leave HTML and all
it's legacy behind. Is this possible?
No, it is not possible. But you can have the resulting document out of
your XML data in XHTML format - if it makes you feel more advanced. But
I would stay with HTML: "tag soup", "legacy trash" etc. is in the
heads, not in HTML itself. Why not to make a perfectly clear correct
template?

About alert() in the particular: it is actually
window.alert() (a method of the host object). So you want DOM, but w/o
DOM? The bird won't fly this way ;-)
XML doesn't have DOM, it is just a data source as I said already. It
has though a node-based structure you can handle /during the
transformation into resulting document/ using XPath.

Jul 20 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.