Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-07-07
7
Medium Priority
?
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 39

Accepted Solution

by:
abel earned 1000 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

636 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