?
Solved

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

Posted on 2009-07-07
7
Medium Priority
?
250 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

770 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