Link to home
Start Free TrialLog in
Avatar of Samm1502
Samm1502

asked on

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

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

 
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gertone (Geert Bormans)
<xsl:value-of select="myjs:CheckValid(string(Cell[31]/Data), string({$charregexp}), string
   ('char'))"/>

you need to escape the XPath with {} (attribute value templates)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of Samm1502
Samm1502

ASKER

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
You're welcome, so actually the regex itself was the problem eventually, well seen, Gertone  ;-)
welcome, sorry again for the confusion in my first message