Solved

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

Posted on 2009-07-07
7
247 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 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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 the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

696 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