Solved

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

Posted on 2009-07-07
7
223 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

708 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

19 Experts available now in Live!

Get 1:1 Help Now