|
Posted by RC on November 14, 2006, 8:34 am
Please log in for more thread options
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
show/hide quoted text
<?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----------------------------------------
show/hide quoted text
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<?xml-stylesheet type="text/xsl" href="test1.xsl" ?>
show/hide quoted text
<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" show/hide quoted text
version="1.0">
<xsl:output method="html" />
show/hide quoted text
<xsl:template match="states">
<form>
<select>
<xsl:apply-templates select="state_code" />
</select>
</form>
</xsl:template>
show/hide quoted text
<xsl:template match="state_code">
<option value="">
<xsl:value-of select="text()" />
</option>
</xsl:template>
show/hide quoted text
</xsl:stylesheet>
|
|
Posted by Martin Honnen on November 14, 2006, 8:48 am
Please log in for more thread options
RC wrote:
show/hide quoted text
> // Now I got an XML object here
> var xmlDocument = XMLHttpRequestObject.responseXML;
show/hide quoted text
> 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.
show/hide quoted text
> 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
>
> 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:
show/hide quoted text
<http://developer.mozilla.org/en/docs/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations>
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/
|
|
Posted by Thomas Wittek on November 14, 2006, 12:06 pm
Please log in for more thread options
RC schrieb:
show/hide quoted text
> The problem is DOM requires you are an excellent JavaScript programmer
Take a look at the http://jquery.com/ lib. Very handy.
show/hide quoted text
> 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
|
|
Posted by Harlan Messinger on November 14, 2006, 12:18 pm
Please log in for more thread options
RC wrote:
show/hide quoted text
> 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.
|
| Similar Threads | Posted | | AJAX IDE--The Release of JoyiStar AJAX WebShop 3 Beta | December 13, 2006, 12:20 am |
| Dealing with overriding styles with stylesheets in Microsoft Word | November 19, 2004, 7:28 am |
| Group for AJAX? | February 20, 2006, 11:45 am |
| Picker (Ajax?) | July 14, 2006, 5:38 am |
| PC IE6 & Prototype AJAX | October 28, 2006, 8:16 pm |
| Recommend an AJAX IDE | January 9, 2007, 2:04 am |
| using ajax, form and MySQL? | January 24, 2008, 6:39 am |
| closing page with AJAX | March 7, 2008, 11:44 am |
| how to style an AJAX-loaded fragment | November 22, 2009, 1:10 pm |
| how to style an AJAX-loaded fragment | November 22, 2009, 1:28 pm |
|