[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

search and replace along with apply-templates

Subject: search and replace along with apply-templates
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Sun, 19 Nov 2000 07:55:37 -0800
leon chester
I have some JavaScript functions that, on click of a glossed word, open a
new window and writes to it with document.write.  That all works fine except
there is potential for it to break if the defintion contains a single quote.
Is there some way to apply-templates and search for the single quote
character and prepend the js escape character "\" to the single quote?

 Below is where I put together the JS for the switch(case) statement:

<xsl:template match="glossentry">
   <xsl:variable name="theword" select="normalize-space(glossterm)"/>
   case "<xsl:value-of select="$theword"/>":
      item = '<b><xsl:value-of select="$theword"/></b><br/><br/>';
<!-- this part could contain a single quote  -->
      def = '<xsl:apply-templates select="glossdef/example/para"
mode="glossary"/>';
      break;
</xsl:template>

an example of the output:

   case "expatriate":
      item = '<b>expatriate</b><br><br>';
      def = 'The French <i>expatriates</i> in the U.S. got together to
celebrate Bastille Day.<br><br>While managing his company's operations in a
small town southeast of Paris, Leon Chester, then an American
<i>expatriate</i>, noticed that his French colleagues shook hands every
morning.<br><br>';
      break;
--------

This will fail is JS because of the single quote after "<br>While managing
his company's ".  Is there a way to search the string delivered by:

<xsl:apply-templates select="glossdef/example/para" mode="glossary"/>

and escape any single quotes, for example:

   case "expatriate":
      item = '<b>expatriate</b><br><br>';
      def = 'The French <i>expatriates</i> in the U.S. got together to
celebrate Bastille Day.<br><br>While managing his company\'s operations in a
small town southeast of Paris, Leon Chester, then an American
<i>expatriate</i>, noticed that his French colleagues shook hands every
morning.<br><br>';
      break;

tia,
Rob


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.