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.