473,698 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can AJAX dealing with XSLT instead DOM?

RC
Let's say:

if (XMLHttpRequest Object.readySta te == 4 &&
XMLHttpRequestO bject.status == 200)
{
// Now I got an XML object here
var xmlDocument = XMLHttpRequestO bject.responseX ML;
// next I have dealing with XML file tags used DOM.
var options = xmlDocument.get ElementsByTagNa meNS(null,"myXM LTag");
doMyFunctionWit hHTMLDOM(option s);
}

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="myXSLTFil e.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>N Y</state_code>
<state_code>N J</state_code>
<state_code>N M</state_code>
<state_code>N C</state_code>
<state_code>N H</state_code>
</states>

------------XSLT-----------------------------------------------
<xsl:styleshe et 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_c ode" />
</select>
</form>
</xsl:template>

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

</xsl:stylesheet>
Nov 14 '06 #1
4 1556
RC wrote:
// Now I got an XML object here
var xmlDocument = XMLHttpRequestO bject.responseX ML;
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="myXSLTFil e.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.mozil la.org/en/docs/Using_the_Mozil la_JavaScript_i nterface_to_XSL _Transformation s>
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, transformNodeTo Object, 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

Martin Honnen wrote:
RC wrote:
// Now I got an XML object here
var xmlDocument = XMLHttpRequestO bject.responseX ML;

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="myXSLTFil e.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.
Amen to that. They're much worse IMHO...
>
Mozilla's XSLT processor API is documented here:
<http://developer.mozil la.org/en/docs/Using_the_Mozil la_JavaScript_i nterface_to_XSL _Transformation s>
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, transformNodeTo Object, 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 #3
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 #4
RC wrote:
Let's say:

if (XMLHttpRequest Object.readySta te == 4 &&
XMLHttpRequestO bject.status == 200)
{
// Now I got an XML object here
var xmlDocument = XMLHttpRequestO bject.responseX ML;
// next I have dealing with XML file tags used DOM.
var options = xmlDocument.get ElementsByTagNa meNS(null,"myXM LTag");
doMyFunctionWit hHTMLDOM(option s);
}

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 #5

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

Similar topics

17
1805
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...
3
1686
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);
3
1846
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);
0
8608
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
9161
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...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8867
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
7732
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...
1
6522
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
4370
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
3050
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
2332
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.