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 July 11th, 2008, 03:53 AM
and and is offline
Registered User
 
Join Date: Jul 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to add " " inside a method({ })

Hello,

I want to insert " " to the . which have the text i am interested in.
copyToClipboard is a javascript.
Code:
<xsl:template match="xxx">
  <input type="button" VALUE="Copy to clipboard" onClick="copyToClipboard({.})"></input>

What I get with this code is for example, Text to be copied
but this isn't a string so it don't get copied to the clipboard

What i want is something like this:
Code:
<xsl:template match="xxx">
  <input type="button" VALUE="Copy to clipboard" onClick="copyToClipboard({"."[u]</u>})"></input>

So i get, "Text to be copied"

 
Old July 11th, 2008, 04:07 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try

onClick='copyToClipboard("{.}")'



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 11th, 2008, 04:21 AM
and and is offline
Registered User
 
Join Date: Jul 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the answer.

I get a strange output in the HTML document after I tried your solution.

Code:
 <input type="button" VALUE="Copy to clipboard" onClick="copyToClipboard(&quot;Text to be copied&quot;)">
 
Old July 11th, 2008, 04:30 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Try using single quotes instead then onclick="copyToClipboard('{.}')"

/- Sam Judson : Wrox Technical Editor -/
 
Old July 11th, 2008, 04:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Unfortunately &quot; ought to be OK here, but Javascript can be a bit fussy. It's safest to keep the Javascript that you generate in HTML attributes extremely simple, which might sometimes mean generating a call to a function that actually appears in your <script> section. Some serializers are better than others at coping with the foibles of Javascript.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 11th, 2008, 09:15 AM
and and is offline
Registered User
 
Join Date: Jul 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello and thanks again,
The single quotes didn't work so I thought of changing in the JavaScript but that didn't work the way I did it.
Any idea how to correct it?
I added the second row:
Code:
copyToClipboard = function(txt) {
    var txtcor = txt.toString();

The error Firefox 3 gave me in the error console:
Code:
Error: illegal character
Source File: file:///xxx.htm
Line: 2, Column: 8
Source Code:
        #include xxx

And the error console had an arrow pointing after the #
#include xxx is what I previously have called Text to be copied

 
Old July 11th, 2008, 09:21 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

No closing brace on the function body. Although if the single quote solution isn't working then either the text has quote marks in it or there's something else wrong in the code.

--

Joe (Microsoft MVP - XML)
 
Old July 14th, 2008, 03:27 AM
and and is offline
Registered User
 
Join Date: Jul 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again for the answers.
Your solutions worked but I have found a new error, but don't know how to correct it.
The problem is that it only works on one row like this.
Code:
<input type="button" VALUE="Copy to clipboard" onClick='copyToClipboard("Text to be copied")'></input>
But not on two or more rows like this:
Code:
<input type="button" VALUE="Copy to clipboard" onClick='copyToClipboard("Text to 
be copied")'></input>
The error I get is:
Code:
Error: unterminated string literal
Source File: file:///xxx.htm
Source Code:
copyToClipboard("Text to
Edited: Figured out JavaScript can't have Strings with line breaks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can’t add method to class in C#? arbab BOOK: Beginning C# 2005 Databases 0 September 29th, 2008 07:35 AM
Calling a method defined inside a .NET dll rajen C# 5 January 7th, 2008 04:04 AM
add method to control travlos Access VBA 2 August 4th, 2007 02:09 AM
Calling a method defined inside a .NET dll rajen C# 2005 0 September 19th, 2006 12:58 AM





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