473,769 Members | 6,831 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 5243
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
2018
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
1845
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
1761
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
1843
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
3162
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
1688
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
2363
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
2262
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
9590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
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
10000
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,...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
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...
1
3968
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
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.