This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

search and replace along with apply-templates


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]