Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2012, 10:19 AM
Registered User
 
Join Date: Jan 2012
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Default Set XSL value inside JavaScript

Hello Everyone,

I have one <a> link and I am calling one Javascript method "toggleMe" on onclick even. This Javascript methods takes 2 parameters. I want to set XSL value in these parameter. It throws error in XSLT file if I try.

I am using below link in <xsl:for-each select="report/script">

<a onclick='return toggleMe(<xsl:value-of select="bcname"/>,"UserName")'>

Please let me know, how I can do this action.

Thanks in advance.

Regards,
Rajeev
 
Old January 31st, 2012, 10:21 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can't embed XSLT inside an attribute like that, but you can use the xsl:attribute instruction.

Code:
<a>
<xsl:attribute name="onclick">return toggleMe('<xsl:value-of select="bcname"/>', 'UserName')</xsl:attribute>
</a>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
RRANJAN (February 2nd, 2012)
 
Old January 31st, 2012, 10:23 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Use an attribute value template e.g.
Code:
<a onclick="return toogleMe({bcname}, 'UserName');">...</a>
to meet XSLT syntax requirements.
To meet Javascript syntax requirements, you might need
Code:
<a onclick="return toogleMe('{bcname}', 'UserName');">...</a>
depending on the type of value you want to pass in (i.e. a string).
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
RRANJAN (February 2nd, 2012)
 
Old February 2nd, 2012, 12:10 AM
Registered User
 
Join Date: Jan 2012
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks everyone. It worked.





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL: How to get javascript function return SELECT value in xsl ojoker XSLT 5 May 24th, 2011 11:52 AM
Set xsl variable using Javascript variable Kunn XSLT 5 December 31st, 2008 02:43 AM
XSL Params inside When Test shasto100 XSLT 3 April 21st, 2006 05:45 AM
USING PARAMETER INSIDE XSL:TEXT cleytonjordan XSLT 6 July 29th, 2005 07:30 PM
set ASP variable values inside Javascript crmpicco HTML Code Clinic 1 March 9th, 2005 12:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.