473,387 Members | 3,821 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,387 software developers and data experts.

XSLT transform of XHTML page content in Internet Explorer

Summary: Can I do an XSLT transform, in the client, of a tree of nodes
taken from the displayed page DOM in IE? This works in Firefox.

Hi,

I'm just starting the process of rewriting part of a "database frontend"
type of intranet application. The existing table-display code consists
of a mountain of very clever but extremely brittle spaghetti-javascript,
which I'm planning to replace with XSLT transformations. At present I'm
still prototyping things to make sure that everything I want to do is at
least possible.

The display part of the problem is essentially solved (just a Simple
Matter of (XSLT) Programming(tm)), but editing is a little trickier. The
existing app has in-place editing in all the tables - click a button and
the text in the cells is replaced with (filled) textboxes which can be
edited. This I've done less prototyping on, but believe to be fairly
simple - just run the original XML through a different stylesheet to
produce editing widgets instead of text. The problem comes with saving
the data.

At present, the save can be fairly glitchy, as everything that's changed
has to be kept track of in Javascript. This technique would only get
worse with my plans for new and more sophisticated ways of editing the
data in the page. So what I want to do instead is to generate the "save"
message (already exists, currently generated as an XML string by the
Javascript(!)) by comparing, in XSLT, the original data XML and the
current in-page DOM. Thus any and all changes, whether made by hand
editing or by arbitrarily-complicated Javascript DOM updates, will be
captured, and there is no backing store to get out of sync with what the
user can see. Put the data in the page -change it -find the
differences -transmit them.

As a first stage of prototyping, I've tried putting part of the page DOM
(the contents of a div, originally generated by XSLT as it would be in
the scheme above) through a trivial XSLT transform. This works perfectly
in Firefox (well, except that my XSLT-fu is still a little weak, but
that'll improve :-) ) but fails in IE. As far as I can see, this is
because as far as IE is concerned the contents of the page are not XML
(though they're marked as XHTML; not certain the whole thing is valid
but it's mostly generated by Javascript DOM methods). I tried getting
the innerHTML of the div and using DOMDocument.loadXML to create an XML
document, but even though the div was created by writing to innerHTML
with the results of an XSLT transform in the first place, it seems that
the string is no longer valid when read back out of innerHTML. In
particular (and what kills the parser), attributes are no longer
surrounded by double quotes - nice :-/ . I get the impression that the
MSXML suite is pretty sane and compliant, but any attempt to involve
IE-specific stuff is going to be painful.

So, does anyone know if this scheme is possible in IE? Does anyone know
of a more appropriate place to ask this (my (work) server doesn't seem
to carry MS groups)? And does anyone have a suggestion for a better way
of accomplishing the whole task - this is why I've included so much
background information on what I'm doing. Thanks for any help.

Pete
Oct 27 '06 #1
6 2625
* Pete Verdon wrote in comp.text.xml:
>Summary: Can I do an XSLT transform, in the client, of a tree of nodes
taken from the displayed page DOM in IE? This works in Firefox.
Yes, if you use a XSLT implementation designed to do just that (e.g.,
one of the Javascript-based XSLT implementations that work in IE), or
if serialize the DOM into an XML document and load that into the MSXML
engine. Otherwise no.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Oct 27 '06 #2
Bjoern Hoehrmann wrote:
* Pete Verdon wrote in comp.text.xml:
>Summary: Can I do an XSLT transform, in the client, of a tree of nodes
taken from the displayed page DOM in IE? This works in Firefox.
Yes, if you use a XSLT implementation designed to do just that (e.g.,
one of the Javascript-based XSLT implementations that work in IE), or
Thanks for the suggestion; I wasn't aware of such things. Do you have an
example? Also, how do they compare for speed - one of the ways my team
leader is justifying my time spent on this is faster table rendering
(since it's an easier thing for non-developers to understand than the
actually-more-important refactoring angle). The prototype rendering (as
opposed to editing) using MSXML is nice and speedy.
if serialize the DOM into an XML document and load that into the MSXML
engine.
This sounds a little like one of the approaches I tried, if one takes
reading innerHTML to be a form of serialising. Clearly you're referring
to a different way of serialising the IE DOM that I'm not aware of;
could you explain?

Thanks for the quick response.

Pete
Oct 27 '06 #3
Pete Verdon wrote:
Bjoern Hoehrmann wrote:
>if serialize the DOM into an XML document and load that into the MSXML
engine.

This sounds a little like one of the approaches I tried, if one takes
reading innerHTML to be a form of serialising. Clearly you're referring
to a different way of serialising the IE DOM that I'm not aware of;
could you explain?
innerHTML does not serialize according to XML rules but rather SGML
rules so you would have to write your own serialization code (e.g. with
JavaScript) that serializes the IE HTML DOM tree according to XML rules,
then you can feed that result to MSXML and an XML DOMDocument of MSXML.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 27 '06 #4
Martin Honnen wrote:
Pete Verdon wrote:
>Bjoern Hoehrmann wrote:
>>if serialize the DOM into an XML document and load that into the MSXML
engine.
>This sounds a little like one of the approaches I tried, if one takes
reading innerHTML to be a form of serialising. Clearly you're
referring to a different way of serialising the IE DOM that I'm not
aware of; could you explain?
innerHTML does not serialize according to XML rules but rather SGML
rules so you would have to write your own serialization code (e.g. with
JavaScript) that serializes the IE HTML DOM tree according to XML rules,
then you can feed that result to MSXML and an XML DOMDocument of MSXML.
I was afraid someone was going to say that. There's really no way to
treat XHTML (which by definition is XML) as XML?

Pete
Oct 27 '06 #5
Pete Verdon wrote:
I was afraid someone was going to say that. There's really no way to
treat XHTML (which by definition is XML) as XML?
IE can only render XHTML when treating it as text/html so in your case
the result of the XSLT transformation might be XHTML which is
well-formed XML but IE parses it as text/html with its HTML tag soup
parser and the DOM built is IE's HTML DOM and properties like outerHTML
or innerHTML in that DOM are following SGML rules and not XML rules.

The only XML properties in that DOM are
document.XMLDocument
and
document.XSLDocument
which point to the original XML input respectively the XSLT stylesheet
and are MSXML DOM documents.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 27 '06 #6
Martin Honnen wrote:
Pete Verdon wrote:
>I was afraid someone was going to say that. There's really no way
to treat XHTML (which by definition is XML) as XML?
IE can only render XHTML when treating it as text/html so in your
case the result of the XSLT transformation might be XHTML which is
well-formed XML but IE parses it as text/html with its HTML tag soup
parser and the DOM built is IE's HTML DOM
Well, that's me buggered then.
and properties like outerHTML or innerHTML in that DOM are following
SGML rules and not XML rules.
That I expected; trying to read from innerHTML was a bit of a hack that
I thought might just work, after the DOMish ways failed.
The only XML properties in that DOM are document.XMLDocument and
document.XSLDocument which point to the original XML input
respectively the XSLT stylesheet and are MSXML DOM documents.
OK, that's interesting in itself. Obviously it's not useful in this
situation, but it would have saved me keeping my own copy around for the
comparison on the save.

I guess my only options if I want to carry on with this route are
Bjoern's original suggestions - use a non-native XML/XSLT system or
write a Javascript HTML-DOM -XML-string serialiser. Anyone got any
comments on those avenues?

Pete
Oct 27 '06 #7

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

Similar topics

20
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
9
by: Jeff Rubard | last post by:
I am curious to know whether anyone has experience using XSLT for web XML (non-XHTML) styling, either with CSS or standalone. I myself have engaged in rather unsuccessful experiments with the...
3
by: Tim Dempsey | last post by:
Folks, I need some advice. I hpoe some of you can advise me. Our church's weekly bulletin has been published on paper for years. It is created in MS Word and sent to the publishing company....
2
by: Dave Matthews | last post by:
Hi folks, I'm writing a web-page editing tool for my company which will allow staff (with no "technical" expertise) to maintain their own Intranet sites. The content for each webpage is stored...
2
by: FrankStallone | last post by:
I am just getting started in XML and I made my first xml, dtd and xslt file and XML spy said they were all valid and they worked. This was the xslt doc that worked. <?xml version="1.0"...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
2
by: Eric Lindsay | last post by:
Is this still the right place to discuss pages written in XHTML+XML and whether browsers treat them as XML or as HTML? I realise that Internet Explorer doesn't like XHTML pages served as...
21
by: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post by:
It is common knowledge that XHTML is better HTML and you can serve XHTML content as HTML. However, the second statement is incorrect, for various reasons; it is enough to say that the HTML...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.