On Apr 30, 9:53 pm, RobG <r...@iinet.net.au> 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

sl="http://www.w3.org/1999/XSL/
Transform">
<xsl

utput 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.
|
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.