473,320 Members | 1,845 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,320 software developers and data experts.

Can AJAX dealing with XSLT instead DOM?

RC
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);
}

The problem is DOM requires you are an excellent JavaScript programmer
to deal with firstChild, lastChild, nextSibling, etc.
And 2nd problem is different browsers will have different results.
Sometime work in Firefox/Netscape, but not work in IE, etc.

In my XML file has a line
<?xml-stylesheet type="text/xsl" href="myXSLTFile.xsl" ?>

I would like use a very simple XSLT file do the work, no DOM programming
deal with those "children".
So back to my question, How to use AJAX to deal with XSLT instead deal
with DOM?
Thank you very much in advance!

Here is an example of XML and XSLT files, they are working fine.

------------XML----------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<?xml-stylesheet type="text/xsl" href="test1.xsl" ?>

<states>
<state_code>NY</state_code>
<state_code>NJ</state_code>
<state_code>NM</state_code>
<state_code>NC</state_code>
<state_code>NH</state_code>
</states>

------------XSLT-----------------------------------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />

<xsl:template match="states">
<form>
<select>
<xsl:apply-templates select="state_code" />
</select>
</form>
</xsl:template>

<xsl:template match="state_code">
<option value="{text()}">
<xsl:value-of select="text()" />
</option>
</xsl:template>

</xsl:stylesheet>
Nov 14 '06 #1
3 1834
RC wrote:
// Now I got an XML object here
var xmlDocument = XMLHttpRequestObject.responseXML;
The problem is DOM requires you are an excellent JavaScript programmer
to deal with firstChild, lastChild, nextSibling, etc.
Your pure (or core) JavaScript skills don't matter much to manipulate
the DOM, you need to know the document object model and the differences
in the browser implementations.
And 2nd problem is different browsers will have different results.
Sometime work in Firefox/Netscape, but not work in IE, etc.

In my XML file has a line
<?xml-stylesheet type="text/xsl" href="myXSLTFile.xsl" ?>

I would like use a very simple XSLT file do the work, no DOM programming
deal with those "children".
So back to my question, How to use AJAX to deal with XSLT instead deal
with DOM?
I don't think you gain much by moving to XSLT as you still need script
to run the transformation and as the differences in XSLT processor APIs
are worse than the DOM differences. And finally you need to insert the
result of the XSLT transformation into the HTML DOM document.

Mozilla's XSLT processor API is documented here:
<http://developer.mozilla.org/en/docs/Using_the_Mozilla_JavaScript_interface_to_XSL_Tran sformations>
Opera 9 supports the same API.

IE 6 and later use MSXML 3 to support XSLT 1.0, there are different APIs
you can use with MSXML (e.g. transformNode, transformNodeToObject, and
an XSLT processor API to set parameters).

Opera 8 does not support client side XSLT 1.0. Nor do IE 5 and 5.5
unless MSXML 3 is installed in addition to IE.

Safari/Konqueror I think support client-side XSLT but have no API
exposed to JavaScript.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 14 '06 #2
RC schrieb:
The problem is DOM requires you are an excellent JavaScript programmer
Take a look at the http://jquery.com/ lib. Very handy.
I would like use a very simple XSLT file do the work, no DOM programming
deal with those "children".
Why not apply the XSLT on the server side before sending it to the client?

-Thomas
Nov 14 '06 #3
RC wrote:
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);
}

The problem is DOM requires you are an excellent JavaScript programmer
to deal with firstChild, lastChild, nextSibling, etc.
That doesn't require extensive Javascript knowledge. It does require
knowledge of the DOM--which isn't more complex than XSLT and XPATH.
Besides that, you have to use Javascript to apply the XSLT
transformation anyway, as well as to accomplish whatever update of the
current page needs to occur after the transformation is complete. *That*
requires you to program with the HTML DOM--and if you know how to do
that, then you pretty much know how to use the pertinent features of the
XML DOM too.
Nov 14 '06 #4

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

Similar topics

4
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x =...
17
by: psimakov | last post by:
I wrote a small piece about AJAX without XML. http://www.softwaresecretweapons.com/jspwiki/Wiki.jsp?page=AJAXWithoutXML Is anybody else doing it? Please share your thoughts...
2
by: Tony Rice | last post by:
I"d like to hear critiques on the following method for dealing with the back button and bookmarkability problem with AJAX. Whenever I do something on a page with ajax, I add to...
0
by: melledge | last post by:
Ajax Developers' Day added to XTech 2006 agenda XTech 2006 - 17-19 May - Hotel Grand Krasnopolsky - Amsterdam, The Netherlands
0
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...
6
by: petermichaux | last post by:
Hi, Reading the Yahoo! UI AJAX library, there is a unique workaround for an apparent IE 6 memory leak with binding a function to onreadystatechange. Instead of binding a function to...
3
by: OJ | last post by:
Hi, I have written a small C# 2.0 DLL which acts as a client to a Socket based server over the internet. I have written both synchronous and asynchronous methods to connect, send, and receive data...
3
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...
2
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.