How best to apply XSL to responseXML from XMLHttpRequest??

J

j_mckitrick

Hi all,

I'm making Ajax-type calls that return XML, and rather than parsing the
XML with DOM and building the nodes by hand, it seems much better and
well-designed to get the XML response, get an XSLT stylesheet, apply it
to the XML, and insert the resulting node (containing an HTML table)
into the document at a div.

But I keep getting javascript errors about not being able to insert the
document at this point in the hierarchy, and also XML parsing errors.
This is tough to debug, so I'm looking for advice. Any takers?

TIA,
Jonathon
 
M

Martin Honnen

I'm making Ajax-type calls that return XML, and rather than parsing the
XML with DOM and building the nodes by hand, it seems much better and
well-designed to get the XML response, get an XSLT stylesheet, apply it
to the XML, and insert the resulting node (containing an HTML table)
into the document at a div.

Mozilla does support that approach if you use transformToFragment, see
<http://www.mozilla.org/projects/xslt/js-interface.html>
Here is an example:
<http://home.arcor.de/martin.honnen/operaBugs/op9/XSLT/transformToFragment1.html>
Opera 9 preview also implements the API Mozilla has but what I have
tested so far while they have the methods like transformToFragment
implemented the results might differ from what Mozilla does. But as that
is only a preview of Opera 9 I am rather sure they improve that before
version 9 will be released.
IE with MSXML (3 and later) does not implement anything to produce nodes
with XSLT that could be inserted into a HTML document. Rather with MSXML
you need to use transformNode to get a string result and then use
properties (e.g. innerHTML, outerHTML) or methods (e.g.
insertAdjacentHTML) IE exposes to parse HTML snippets into nodes
inserted into the HTML document.
But I keep getting javascript errors about not being able to insert the
document at this point in the hierarchy, and also XML parsing errors.

You will need to provide more details on your code and on which browser
gives exactly which error. Post a URL if you have but do some work
yourself to isolate the problems to simple cases you can't solve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top