Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 10th, 2006, 04:45 PM
scoomey
Guest
 
Posts: n/a
Default XML, XSLT and modifying the DOM w/Javascript

Hi folks, I've got what I think is an interesting problem that I'm
having trouble finding a solution for. I have an XML document that I
render to the browser via an XSLT transformation to XHTML. I want the
output to include links to a JavaScript routine that I will write to
modify the original XML, but it seems that once the XML is rendered to
XHTML it is no longer in scope of the DOM; only the XHTML output is. IS
there any way to get DOM-level access to the original XML?

Thanks,

Shawn

  #2  
Old March 10th, 2006, 04:55 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: XML, XSLT and modifying the DOM w/Javascript


scoomey wrote:
[color=blue]
> I have an XML document that I
> render to the browser via an XSLT transformation to XHTML. I want the
> output to include links to a JavaScript routine that I will write to
> modify the original XML, but it seems that once the XML is rendered to
> XHTML it is no longer in scope of the DOM; only the XHTML output is. IS
> there any way to get DOM-level access to the original XML?[/color]

Are you using client-side XSLT, that is you let the browser transform
the XML? In that case with IE 6 and MSXML 3 the original XML DOM
document is exposed as the property
document.XMLDocument
of the HTML DOM document.


--

Martin Honnen
http://JavaScript.FAQTs.com/
  #3  
Old March 10th, 2006, 05:05 PM
scoomey
Guest
 
Posts: n/a
Default Re: XML, XSLT and modifying the DOM w/Javascript

Bingo! Thanks Martin.That's exactly what I am doing. I'm going to gove
that a try. I wish there was a cross-browser way to get to the XML
tree, but if not I can live with IE6.

  #4  
Old March 10th, 2006, 07:15 PM
scoomey
Guest
 
Posts: n/a
Default Re: XML, XSLT and modifying the DOM w/Javascript

It worked perfectly. I was able to modify the underlying XML without a
problem... however, is there a way now to "re-apply" the XSL
transformation so that the view reflects the changes to the underlying
XML DOM?

thanks!

  #5  
Old March 11th, 2006, 02:55 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: XML, XSLT and modifying the DOM w/Javascript



scoomey wrote:
[color=blue]
> I was able to modify the underlying XML without a
> problem... however, is there a way now to "re-apply" the XSL
> transformation so that the view reflects the changes to the underlying
> XML DOM?[/color]

That is possible in theory as those are MSXML DOMDocument objects with
e.g. a transformNode method so you have
document.XMLDocument
and
document.XSLDocument
as well where then
document.XMLDocument.transformNode(document.XSLDoc ument)
would give you the string result of the new transformation. Thus if you
only want to do that once then
function showTransformation () {
var xmlDocument = document.XMLDocument;
var xslDocument = document.XSLDocument;
document.open();
document.write(xmlDocument.transformNode(xslDocume nt));
document.close();
}
showTransformation()
should do.

But in general you probably don't want to run the complete
transformation and overwrite the complete document but rather you might
want to change some part of the XML and then update only part of the
HTML document. There is however no direct support for that, you will
somehow need to build your own update function and mechanism.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles