Subject: RE: [xsl] How can I put some javascript into an xslt page From: "Passin, Tom" <tpassin@xxxxxxxxxxxx> Date: Tue, 17 Jun 2003 12:44:08 -0400 |
[Lionel Crine] > I'm using xalan as salt parser. Interesting. I use it as a pepper parser, myself :-) > > > Here is what I tried but the value nbuser is not found. > > > <xsl:template match="users"> > <xsl:variable name="nbuser">hello</xsl:variable> > <script language="javascript"> > function lionel() { document.write(string($nbuser)); } > </script> > <script language="javascript">lionel();</script> > > ... Have you examined the output to see if it is what you intended? Your example will produce the following javascript code: <script language="javascript"> function lionel() { document.write($nbuser); } </script> Your javascript interpreter will not understand $nbuser. If you want the xslt processor to do anything you have to give it an xslt instruction. $nbuser is not an xslt instruction by itself. Probably you want this: function lionel() { document.write(string(<xsl:value-of select='$nbuser'/>)); } As a minor point, there is no reason to use a second script element for the second command. Just put them both in a single script element. As a point of javascript, you do not want to use string() If you thought that you needed it for the xslt side of the house, xsl:value-of will produce a string for you anyway. As a point of xslt, you can declare your variable like this instead - <xsl:variable name='nbuser' select='"hello"'/> This is slightly preferable because it really does make the variable to contain a string. The other way it contains a Result Tree Fragment that ha a text node, which then gets converted to a string. Notice the quotation marks around "hello" in shorter form. If you omit them, the variable will contain a nodeset of elements corresponding to the XPATH expression hello. It will be an empty node set because you have no elements named hello. So make sure to use quotes when you want a string value within an xslt attribute. Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How can I put some javasc, Martinez, Brian | Thread | [xsl] xsl:number problem, Yan, Charlene |
Re: [xsl] How can I put some javasc, Jeni Tennison | Date | RE: [xsl] doctype declaration and m, Whitney, Dan (CanWes |
Month |