473,881 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ajax, xml and applying xslt

I have the following that outputs an xml file to a div using ajax:

<script type="text/javascript">

function ajaxXML(url,con trol_id){
if (document.getEl ementById) {
var x = (window.ActiveX Object) ? new
ActiveXObject(" Microsoft.XMLHT TP") : new XMLHttpRequest( );
}
if (x) {
x.onreadystatec hange = function()
{
if (x.readyState == 4 && x.status == 200)
{
el = document.getEle mentById(contro l_id);
el.innerHTML = x.responseText;
}
}
x.open("GET", url, true);
x.send(null);
}
}

</script>

<body onload="ajaxXML ('XMLSample.xml ','xmlOutPut')" >
<div id="xmlOutPut" >
</div>
</body>

My question is the xml file has a stylesheet reference in it:
<?xml-stylesheet type="text/xsl" href="XMLSample .xslt"?>

when I open the xml file in a browser, it applies the styesheet, but
when I process it using ajax in the above example, the stylesheet/xslt
is ignored. I am new to ajax and I am probably missing something
simple. Any help is appreciated.

Oct 13 '05 #1
4 5255
Stephen wrote:
I have the following that outputs an xml file to a div using ajax:

<script type="text/javascript">

function ajaxXML(url,con trol_id){
if (document.getEl ementById) {
var x = (window.ActiveX Object) ? new
ActiveXObject(" Microsoft.XMLHT TP") : new XMLHttpRequest( );
}
if (x) {
x.onreadystatec hange = function()
{
if (x.readyState == 4 && x.status == 200)
{
el = document.getEle mentById(contro l_id);
el.innerHTML = x.responseText;
}
}
x.open("GET", url, true);
x.send(null);
}
}

</script>

<body onload="ajaxXML ('XMLSample.xml ','xmlOutPut')" >
<div id="xmlOutPut" >
</div>
</body>

My question is the xml file has a stylesheet reference in it:
<?xml-stylesheet type="text/xsl" href="XMLSample .xslt"?>

when I open the xml file in a browser, it applies the styesheet, but
when I process it using ajax in the above example, the stylesheet/xslt
is ignored. I am new to ajax and I am probably missing something
simple. Any help is appreciated.


What is the doctype of the document you are stuffing the XML into?

For your chosen browser(s) and doctype, how many different doctypes
can a single page have?

You are using XMLHttpRequest to get your file and innerHTML to write
it into your document. What happens if you simply place the XML
content inside the div in the page source and load the page?
--
Rob
Oct 13 '05 #2
What is the doctype of the document you are stuffing the XML into?
.net web form (aspx)
For your chosen browser(s) and doctype, how many different doctypes
can a single page have?
I have to admit ignorance here. I am not sure what you mean.
You are using XMLHttpRequest to get your file and innerHTML to write
it into your document. What happens if you simply place the XML
content inside the div in the page source and load the page?
You mean without using XMLHttpRequest? I did try to put the actual content of the xml in the div and got the same result. I think that the web form doesn't know what to do with it (the style sheet part of it) and it will have to be transformed while loading it. Is there method using XMLHttpRequest for applying transformation while loading?


Oct 13 '05 #3


Stephen wrote:

el.innerHTML = x.responseText; when I open the xml file in a browser, it applies the styesheet, but
when I process it using ajax in the above example, the stylesheet/xslt
is ignored.


Well Ajax is no magic to get stuff working dynamically that does not
even work statically.
If you would load a static "HTML document" with e.g.
<div>
<?xml-stylesheet type="text/xsl" href="XMLSample .xslt"?>
<root>
<contents />
</root>
</div>
then you would not get any meaningful results either, the contents of a
HTML <div> element should be some other HTML elements the browser
understands and not some XML elements with some XML processing instruction.

If you want to apply XSLT to an XML input and have the browser render
the result of the XSLT transformation then you would better do the XSLT
transformation on the server.
Client side XSLT is only supported by a few browsers (IE 6, IE 5 only if
someone installs MSXML 3 on the client too, Mozilla, Safari (since
1.3?)) and scripting it only by IE and Mozilla I think.
The only meaningful construct in HTML to have client-side XSLT applied
to some XML document with a xml-stylesheet processing instruction is e.g.
<iframe src="XMLSample. xml"></iframe>
No XMLHttpRequest needed or helpful for that.

If you wanted to use XMLHttpRequest and client-side XSLT then you need
to load both the XML and XSL document and script the transformation and
then use DOM scripting in HTML to insert the result of the
transformation in the document. Mozilla would allow you to use
transformToFrag ment to directly create HTML DOM nodes, with MSXML in IE
you end with a string you can then insert with setting innerHTML or
using insertAdjacentH TML.

The documentation to script XSLT transformations in Mozilla is here:
<http://www.mozilla.org/projects/xslt/js-interface.html>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 13 '05 #4
Thanks for the reply. The iframe one would work because it is loading
the xml in a frame, which would be like loading it directly in the
browser right?
I was having a brain fart, because even in .net you need code to
transform xml. I don't know what made me think a .net web form could
transform xml on it's own. I want to look at the loading both docs as
in your last suggestion, avoiding postbacks as much as possible. This
is for an intranet and we are a IE only shop, but there is always a
"but.." Who knows if a user wouldn't download and install mozilla
firefox. Anyway, i will hit your link you provided and possible
rethink what I am doing. Thanks again.

Oct 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2020
by: Thomas Sommer | last post by:
Hi, I think the following is not possible but maybe (hopefully) I am wrong: I have: <xsl:param name="test"> <tag1>asdfasdf</tag1> <tag2>asdfasdf</tag2> </xsl:param>
0
1853
by: melledge | last post by:
Ajax Developers' Day added to XTech 2006 agenda XTech 2006 - 17-19 May - Hotel Grand Krasnopolsky - Amsterdam, The Netherlands
3
1768
by: Simon Brooke | last post by:
I've been doing XSL transforms, converting XML to HTML, server side since 2000. In those days, clients which could do the transformation client side didn't exist, so whether to transform client-side or server-side wasn't an issue. Recently I've been overhauling the code in order to pass transform to the client wherever possible, and I've hit two problems (i) How do I know whether the client can do transforms? Currently I'm only...
0
1853
by: melledge | last post by:
Ajax Developers' Day to Kick Off XTech 2006 Conference Industry experts offer insight into next generation of the Web ALEXANDRIA, VIRGINIA, USA - April 25, 2006 - In response to the rapidly developing world of Ajax user interfaces on the browser, IDEAlliance (www.idealliance.org) announced today that its annual XTech Conference will kick off on May 16 with Ajax Developers' Day. XTech 2006 (www.xtech-conference.org), to be held May...
31
3186
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked around here? If so, do you know if Ajax.NET can be used without prototype.js? -- "The most convoluted explanation that fits all of the made-up facts is the most likely to be believed by conspiracy theorists. Fitting the
3
1690
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have dealing with XML file tags used DOM. var options = xmlDocument.getElementsByTagNameNS(null,"myXMLTag"); doMyFunctionWithHTMLDOM(options);
2
2367
by: milecimm | last post by:
Hello, I need some help to solve the following problem (if it is possible, that's it): I'm using a xpath expression to programatically get data from my xml file. I want to transform ONLY the resulting nodes using xslt. In my example below I only want the Academic category to be transformed. Is this possible? (please vb.net or c#). Many thanks. My xml file: <categories> <category> <categorynumber>1</categorynumber> ...
2
2271
by: soni2926 | last post by:
hi, does anyone know of any good books on ajax and asp.net, one that teaches ajax itself before jumping in atlas? I wanted to get an understanding of ajax and how to use it, most books i've seen on .net and ajax seem to jump into atlas right away, does anyone know of any that teach ajax itself and then later get into atlas?
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11095
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10812
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10399
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9552
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5780
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.