Re: cloneNode/appendChild and children



On Apr 30, 9:53 pm, RobG <r...@xxxxxxxxxxxx> wrote:

It seems rather pointless to use XSLT to convert XML to XML. Why not
convert it to HTML and save yourself a lot of trouble?

Possibly, but this is a simple mock-up, and I was following samples I
found online.
I was interested in learning a bit about the server-side application
of transforms anyway.

In what circumstance will userRows be null?

When, for instance, the server has finished sending all users.
Right now (again, this is a mock), the server will send
4 user-rows at the time, for a maximum of 4 times.
When it reaches the end of the simulkated users, it leaves
the response stream clear.

Why not send HTML instead of XML and just append the rows to the table
(insert the HTML as the innerHTML of a div to convert it to a DOM
object, just wrap the trs in table tags)? You could also just grab
the tbody and append it to the current table or replace the current
tbody - done in one go.

I actually tried to switch the xsl transformation output from xml to
html, just to see
if it made any difference, but it didn't.
I've been reading around and it seems that, indeed, cloneNode does not
copy
all attributes and/or event handlers (although in my case the href
attribute is cloned),
and that simply adding a node to an [x]html document is not enough.
See for instance this article: http://alistapart.com/articles/crossbrowserscripting
It focuses on importNode, rather than cloning and appending (like I am
doing), but the
problem seem to be the same.

Without seeing the initial XML and the resulting markup I can only
guess.

The source of users is an xml file as follows: (I'll show you a single
user, but there are 4 in the actual file)
<?xml version="1.0" encoding="UTF-8"?>
<ListPage>
<User id="1">
<Login>fred</Login>
<Password>Wilma</Password>
<FirstName>Fred</FirstName>
<LastName>Flinstone</LastName>
</User>
</ListPage>

The xslt, with the first 2 columns set to be links:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-
declaration="no" standalone="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<ListChunk>
<xsl:for-each select="ListPage/User">
<tr>
<td>
<a href="http://www.google.com";><xsl:value-of
select="@id" /></a>
</td>
<td>
<a href="http://www.google.com";><xsl:value-of
select="Login" /></a>
</td>
<td>
<xsl:value-of select="Password" />
</td>
<td>
<xsl:value-of select="FirstName" />
</td>
<td>
<xsl:value-of select="LastName" />
</td>
</tr>
</xsl:for-each>
</ListChunk>
</xsl:template>
</xsl:stylesheet>

Using firebug, I've been checking what gets sent by the server to the
client, and it seems to be:
<ListChunk>
<tr>
<td><a href="http://www.google.com";>1</a></td>
<td><a href="http://www.google.com";>fred</a></td>
<td>Wilma</td>
<td>Fred</td>
<td>Flinstone</td>
</tr>
</ListChunk>


As I said, changing the output method of the transform from xml to
html didn't seem to make any difference.

I can share the whole thing if needed (including the javascript that
kicks off the request on page load, etc etc), but it really seem to me
that there's something going on with the cloneNode/appendChild
sequence.
In the article I mentioned above, A. Holdener explains that

[quote]
Apparently, in all browsers, elements must be passed through the HTML
parser before events and style will be activated.
[/quote]

That might be the reason why the links are not being treated as links
(but reloading the page from a local copy makes them act like proper
links).
Or maybe not, maybe it's totally unrelated and I'm missing something
else.

Do not feed XML to IE.

....so what's the recommended cross-browser 'closest-to-standard-
compliance' approach to take for something like this ?

Thanks for reading and answering,
F.O.R.


.



Relevant Pages

  • Re: XML Transformation Effectiveness.
    ... > I was actually looking for a server independant app like TiddlyWiki. ... > user to take the html document anywhere with them without being ... > The thing I want to do is very similar, accept I want to add an XML ... XML/XHTML), XHTML is a subset of XML. ...
    (comp.lang.javascript)
  • Re: Newbie, HTML calling XSLT
    ... I would like to write a simple HTML page that calls ... > XSLT and passes it parameters. ... other flavour of XML) because XSLT 1.0 only processes XML. ... > programming language like Perl or php to achieve this? ...
    (comp.text.xml)
  • Re: XHTML Doctype?
    ... One friend has said "but you just use XSLT to translate it into ... HTML -- that's not really serving XML, ...
    (comp.text.xml)
  • Re: onclick - reassign new function with parameters after displaye
    ... It creates an HTML document which looks and acts correctly. ... The orginal XSL is creating a record that shows data from two different ... The form reads in those global variables. ... XML Node that forms the context of your little XSL. ...
    (microsoft.public.scripting.jscript)
  • Zeichenkodierung der Ausgabe beim "href" Attribut
    ... mit Hilfe von LibXSLT wird eine HTML Seite in ISO-8859-1 Kodierung ... Nun ist ein Link auf eine Datei hinzugekommen, ... Der Dateiname steht im XML Dokument. ... Aus irgendeinem Grund scheint der XSLT Prozessor -- ich habe auch Xalan ...
    (de.comp.text.xml)