Solved

How to pass a string containg value $ to a javascript call in XSLT style sheet

Posted on 2009-07-07
7
227 Views
Last Modified: 2013-11-18
Hi there

I need to make a call to a Javascript function in my style sheet that does regular expression matching as I have to use XSL version 1.0 at the moment.  All works fine except when I nee dto pass a regular expression such as the following to the function:

<xsl:param name="charregexp" select=" '^[A-Za-z0-9. -]$'"></xsl:param>

call looks like this:

<xsl:if test="normalize-space(Cell[31]/Data) != ''">
  <xsl:value-of select="myjs:CheckValid(string(Cell[31]/Data), string($charregexp), string
   ('char'))"/>      
</xsl:if>

Basically the call doesn't handle the $ in charregexp because it is a syntax character so how do I include it in my regular expression?  I have tried adding an escapr character but that doesn't help.

Many thanks
Sam

 
0
Comment
Question by:Samm1502
  • 4
  • 2
7 Comments
 
LVL 39

Accepted Solution

by:
abel earned 250 total points
ID: 24792158
You can simply use the dollar sign inside a string, there's nothing in XSLT that stops you from doing so. The $ is also the start of a parameter or variable name inside an XPath but you use a string literal, so that doesn't matter here and escape characters are not needed.

You say it doesn't work, can it be that something else is the problem? Do you get an error and if so, which? How does the javascript function look? If this is MSXML, is scripting then enabled (not all versions require this)? Can you show a larger part of you XSLT that illustrates the full problem?

-- Abel --
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24792197
<xsl:value-of select="myjs:CheckValid(string(Cell[31]/Data), string({$charregexp}), string
   ('char'))"/>

you need to escape the XPath with {} (attribute value templates)
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 250 total points
ID: 24792224
ignore my comment, I did not check carefully enough, my comment would hold true if you had to escape the param in an attribute, sorry

the microsoft scripting engine does weird things with regular expressions sometimes, I had my share of curses there :-),
but maybe simply the regex is wrong... there could be a space preceding the end of string, try to change it like this
<xsl:param name="charregexp" select=" '^[A-Za-z0-9. -]+.*$'"></xsl:param>
Note that I also put a '+' after the character class, if not you are only looking for one character there

as abel rightly says, the $ in the string is just an ordinary character, no problem to be expected from the XSLT end
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24792234
of course I am guessing what is in 'char',
make sure it really is only one character if you want your own regex to work
0
 

Author Closing Comment

by:Samm1502
ID: 31600498
Thanks guys.  Firstly yes I think I had an extra space that i couldn't see for looking at it too long and secondly I did need the + after my regexp so many thanks for that too. Cheers Sam
0
 
LVL 39

Expert Comment

by:abel
ID: 24792523
You're welcome, so actually the regex itself was the problem eventually, well seen, Gertone  ;-)
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24792568
welcome, sorry again for the confusion in my first message
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS Question.. 3 77
File names with & character 6 70
How to get statistic's from a competitors website?! 1 85
Element alignment and word wrapping 9 60
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now