You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Lincoln Mitchell <li...@interfaces-n-creatives.com> on 2008/02/13 22:20:55 UTC
Using xsl variables in javascript
Hi all,
I am trying to use an xsl parameter in an external javascript file.
Do I have to use Control Flow / Flowscript to achieve this?
The docs say Control Flow is about ".the ability to describe the order of
Web pages." and in my case I don't need to do this.
I simple need to convert this inline javascript:
<script type="text/javascript">
function myFunction(){
<xsl:choose>
<xsl:when test=" $myParam='x'">
alert('x')
</xsl:when>
</xsl:choose>
}
</script>
.to an external javascript file like:
function myFunction(){
if ($myParam='x'){
alert('x')
}
}
Thanks for any help on the issue.
Linc
Re: Using xsl variables in javascript
Posted by Tobia Conforto <to...@linux.it>.
Lincoln Mitchell wrote:
> I simple need to convert this inline javascript:
>
> <script type="text/javascript">
> function myFunction(){
> <xsl:choose>
> <xsl:when test=" $myParam='x'">
> alert('x')
> </xsl:when>
> </xsl:choose>
> }
> </script>
>
> …to an external javascript file like:
>
> function myFunction(){
> if ($myParam='x'){
> alert('x')
> }
> }
I don't think you have execution times very clear. XSLT code runs on
your server at pipeline execution time, before or during page
generation. Client javascript code runs in the client browser at page
rendering time, after page generation and transmission. This means
that whatever comes out of your pipeline must be well-formed HTML and/
or Javascript that will run on the browser, without access to any XSLT
or Cocoon variables. In fact, by the time the generated HTML reaches
the browser, the variables used in your XSLT won't exist anymore.
Nevertheless, it might be that what you're after is simply this:
<script type="text/javascript">
var myParam = "<xsl:value-of select="$myParam"/>";
</script>
Notice the extra quotation marks around the value-of: this XSLT code
is generating a HTML script tag containing Javascript code that, when
run by the browser, will declare a global string variable called
myParam. From that moment on, every piece of Javascript code run on
the browser will have access to that global variable.
Also, this is generic web programming matter, not exactly related to
Cocoon.
Tobia
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Using xsl variables in javascript
Posted by Bhavya Sharma <bh...@gmail.com>.
As i think first you need to take the value of xsl variable into a
javascript variable , that you can do like this
<script language="javascript">
var mparam="<xsl:value-of select='$myparam'/>";
if(mparam=='x')
{
// your statement
}
</script>
On Feb 14, 2008 2:50 AM, Lincoln Mitchell <
lincoln@interfaces-n-creatives.com> wrote:
> Hi all,
>
> I am trying to use an xsl parameter in an external javascript file.
>
> Do I have to use Control Flow / Flowscript to achieve this?
>
> The docs say Control Flow is about "…the ability to describe the order of
> Web pages…" and in my case I don't need to do this.
>
> I simple need to convert this inline javascript:
>
> <script type="text/javascript">
>
> function myFunction(){
>
> <xsl:choose>
>
> <xsl:when test=" $myParam='x'">
>
> alert('x')
>
> </xsl:when>
>
> </xsl:choose>
>
> }
>
> </script>
>
>
>
> …to an external javascript file like:
>
> function myFunction(){
>
> if ($myParam='x'){
>
> alert('x')
>
> }
> }
>
>
>
> Thanks for any help on the issue.
>
>
>
> Linc
>
--
Thanks
Bhavya Sharma