semantic_c0d3r
semantic_c0d3r

Reputation: 801

How to pass xsl variable as a parameter to javascript function within script tag?

I have tried the following code :

<xsl:variable name="xx" select="'40967.6424503935'"/>
<script type="text/javascript">
   time({$xx});
</script>

My intention is to display text via document.write() present in time(). But it didnt give any result.

Upvotes: 4

Views: 9213

Answers (3)

Oleg
Oleg

Reputation: 21

<input type="hidden" id="title" select="{COL[@name='title']}"/>

<script type="text/javascript">
    alert(document.getElementById('title').value);
</script>

This works for me.

Upvotes: 0

user3398993
user3398993

Reputation: 11

There should be a small correction in the above code snippet. The parameter should be passed within single inverted comma.

<xsl:variable name="xx" select="'40967.6424503935'"/>
<script type="text/javascript">
   time('<xsl:value-of select="$xx" />');
</script> 

This will work.

Upvotes: 1

Tim C
Tim C

Reputation: 70648

The curly braces are for 'Attribute Value Templates', but in this case you are not creating an attribute here, just a normal text node. I think you need to do something like this

<xsl:variable name="xx" select="'40967.6424503935'"/>
<script type="text/javascript">
   time(<xsl:value-of select="$xx" />);
</script> 

Upvotes: 6

Related Questions