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>defaul t</title>
<script language="javas cript">
<!--
function DoTransform()
{
var data = new ActiveXObject(" Microsoft.XMLDO M");
data.async = false;
var dataUrl = "data.aspx" ;
var last = document.getEle mentById("last" );
data.load(dataU rl) ;
var transform = new ActiveXObject(" Microsoft.XMLDO M");
transform.async = false ;
transform.load( "discussion.xsl t");
result.innerHTM L = data.transformN ode(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="javas cript">
<!--
DoTransform();
// -->
</script>
</form>
</body>
</HTML>
----------------------------------------------------------------------------
-
data.aspx (result sent to the client using dataset.writexm l):
----------------------------------------------------------------------------
-
<?xml version="1.0" standalone="yes "?>
<MessagesDataSe t xmlns="http://www.tempuri.org/MessagesDataSet .xsd">
<Messages>
<MessageID>9</MessageID>
<Author>steve </Author>
<Body>Bonjour </Body>
<TimeStamp>20 04-08-11T16:46:52.215 0393+02:00</TimeStamp>
</Messages>
............... ............... ........
............... ............... ........
</MessagesDataSet >
----------------------------------------------------------------------------
-
and my xslt file
----------------------------------------------------------------------------
-
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:m="http://www.tempuri.org/MessagesDataSet .xsd">
<xsl:template match="/m:MessagesDataS et">
<table border="1">
<tr>
<td>auto</td>
<td>body</td>
</tr>
<xsl:apply-templates />
</table>
<xsl:for-each select="m:Messa ges">
<script language="javas cript">
alert('<xsl:val ue-of select="m:Messa geID" />');
</script>
</xsl:for-each>
</xsl:template>
<xsl:template match="m:Messag es">
<tr>
<td>
<b>
<xsl:call-template name="format-date">
<xsl:with-param name="date" select="m:TimeS tamp" />
</xsl:call-template>
</b>
<xsl:value-of select="m:Autho r" />
</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='substri ng($date, 1, 4)' />
<xsl:variable name="YY" select='substri ng($date, 3, 2)' />
<xsl:variable name="MM" select='substri ng($date, 6, 2)' />
<xsl:variable name="hh" select='substri ng($date, 12, 2)' />
<xsl:variable name="mm" select='substri ng($date, 15, 2)' />
<xsl:variable name="ss" select='substri ng($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********@hot mail.com> a écrit dans le message de news:
Oq************* *@TK2MSFTNGP11. phx.gbl...
"Steve B." <n.************ *@airsoftconsul ting.com> wrote in message
news:uh******** *****@TK2MSFTNG P09.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.XMLDO M");
data.async = false;
var dataUrl = "data.aspx" ;
data.load(dataU rl) ;
var transform = new ActiveXObject(" Microsoft.XMLDO M");
transform.async = false ;
transform.load( "discussion.xsl t");
result.innerHTM L = data.transformN ode(transform);
result is a div.
Somewhere in my xsl file I have a script that is repeated many times:
<xsl:for-each select="m:Messa ges">
...sometext...
<script language="javas cript">
alert('<xsl:val ue-of select="m:Messa geID" />');
</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"actua lly 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)