473,395 Members | 1,377 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,395 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 1655
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

0
by: Adam Retter | last post by:
Hi Guys, I have a need to create a html form based on my schema. I initially decided to do this using xql, have got some way but am finding this difficult (it may be as I am very new to xql)....
6
by: arfinmail | last post by:
When I read about XSLT for the first time I thought it was a cool toy, but then I asked myself why use XSLT over ASP? Can someone give a real world example where XSLT would be the best choice...
1
by: Sonu Kapoor | last post by:
Hi, I would like to use xpath with xslt. I know that this should be possible, but I dont get it ! Here is what I have tried so far: ==================================== my xml file:...
4
by: Iain | last post by:
Hi all, I am try to split the some data out of a nested xml file and get all the data in one new xml file. I have two XSLT files one takes the personal information and one takes the data out of...
4
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...
1
by: JWHIT | last post by:
I created a map application which works fine with regular aspx and a meta refresh. I would like to have the map itself update independently using ajax. (Sorry on the long post, I just started...
8
by: Jason | last post by:
Hello, I am trying to utilitze the AJAX Control toolkit in my asp.net project. I have added a reference to AjaxControlToolkit.dll, and in my page, added these lines of code: ...
7
by: Paulo | last post by:
Hi, do you think AJAX must used on every system? His only advantage is avoiding post-back on server? Any one who has experience using it ? Please give some directions! Thanks!
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...
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...

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.