XML, CSS and JavaScript

D

Dan H

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 <script> tag, 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?
 
M

Martin Honnen

Dan H wrote:

When I try to include it into the XML as a <script> tag, 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.
 
D

Dan H

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.
 
R

Randy Webb

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.
 
D

Dan H

Randy said:
Dan H said the following on 7/19/2006 3:53 PM:

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.
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?
 
M

Martin Honnen

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.
 
V

VK

Dan said:
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 <script> tag, 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,129
Latest member
FastBurnketo
Top