473,398 Members | 2,525 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,398 software developers and data experts.

XML, CSS and JavaScript

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
6 1351


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

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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.