I'm tring to build a little chat in asp.net.
Since postbacks are awfull for such scenarios, I want to downloads messages
and transforms them in html form, instead of reloading the whole page.
The asp.net codebehind only generates a xml file from a dataset (that's why
my data xml file is a .aspx page).
Here is my current version (I removed useless lines for easyier read)
----------------------------------------------------------------------------
-
default.aspx:
__________
<HTML>
<HEAD>
<title>default</title>
<script language="javascript">
<!--
function DoTransform()
{
var data = new ActiveXObject("Microsoft.XMLDOM");
data.async = false;
var dataUrl = "data.aspx";
var last = document.getElementById("last");
data.load(dataUrl) ;
var transform = new ActiveXObject("Microsoft.XMLDOM");
transform.async = false ;
transform.load("discussion.xslt");
result.innerHTML = data.transformNode(transform);
}
// -->
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" runat="server"
EnableViewState="False"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<div id="result">
</div>
<script language="javascript">
<!--
DoTransform();
// -->
</script>
</form>
</body>
</HTML>
----------------------------------------------------------------------------
-
data.aspx (result sent to the client using dataset.writexml):
----------------------------------------------------------------------------
-
<?xml version="1.0" standalone="yes"?>
<MessagesDataSet xmlns="http://www.tempuri.org/MessagesDataSet.xsd">
<Messages>
<MessageID>9</MessageID>
<Author>steve</Author>
<Body>Bonjour</Body>
<TimeStamp>2004-08-11T16:46:52.2150393+02:00</TimeStamp>
</Messages>
......................................
......................................
</MessagesDataSet>
----------------------------------------------------------------------------
-
and my xslt file
----------------------------------------------------------------------------
-
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:m="http://www.tempuri.org/MessagesDataSet.xsd">
<xsl:template match="/m:MessagesDataSet">
<table border="1">
<tr>
<td>auto</td>
<td>body</td>
</tr>
<xsl:apply-templates />
</table>
<xsl:for-each select="m:Messages">
<script language="javascript">
alert('<xsl:value-of select="m:MessageID" />');
</script>
</xsl:for-each>
</xsl:template>
<xsl:template match="m:Messages">
<tr>
<td>
<b>
<xsl:call-template name="format-date">
<xsl:with-param name="date" select="m:TimeStamp" />
</xsl:call-template>
</b>
<xsl:value-of select="m:Author" />
</td>
<td>
<xsl:value-of select="m:Body" />
</td>
</tr>
</xsl:template>
<xsl:template name="format-date">
<xsl:param name="date">
<xsl:value-of select="." />
</xsl:param>
<xsl:variable name="YYYY" select='substring($date, 1, 4)' />
<xsl:variable name="YY" select='substring($date, 3, 2)' />
<xsl:variable name="MM" select='substring($date, 6, 2)' />
<xsl:variable name="hh" select='substring($date, 12, 2)' />
<xsl:variable name="mm" select='substring($date, 15, 2)' />
<xsl:variable name="ss" select='substring($date, 18, 2)' />
<xsl:value-of select="concat($hh, ':', $mm)" />
</xsl:template>
<xsl:template match="*" />
</xsl:stylesheet>
----------------------------------------------------------------------------
-
I do not want to keep the "alert" method, it was just for testing (it should
call another metod) if the JS is launched.
Thanks,
Steve
"Joe Fawcett" <jo********@hotmail.com> a écrit dans le message de news:
Oq**************@TK2MSFTNGP11.phx.gbl...
"Steve B." <n.*************@airsoftconsulting.com> wrote in message
news:uh*************@TK2MSFTNGP09.phx.gbl... Hello everybody
In a webpage, I use JS display data from an xml file and a xsl file:
var data = new ActiveXObject("Microsoft.XMLDOM");
data.async = false;
var dataUrl = "data.aspx";
data.load(dataUrl) ;
var transform = new ActiveXObject("Microsoft.XMLDOM");
transform.async = false ;
transform.load("discussion.xslt");
result.innerHTML = data.transformNode(transform);
result is a div.
Somewhere in my xsl file I have a script that is repeated many times:
<xsl:for-each select="m:Messages">
...sometext...
<script language="javascript">
alert('<xsl:value-of select="m:MessageID" />');
</script>
</xsl:for-each>
My problem is that the Javascript (alert) is not fired. I don't think
the problem is from my xsl file since the "sometext"actually appears in the
page.
I wonder, if Javascript rendered on the fly is executed. If it is, how
can I do a "execute scripts" or anything like this ?
Thanks !
Steve
I think the problem is that when loading initially inline script is
recognised and run, not when added as innerHTML. Although this is an
untested hypothesis you may need to start the alert boxes yourself. Can
you post a small sample of your source and what you want to be alerted?
--
Joe (MVP - xml)