This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
search and replace along with apply-templates
- To: XSL-List at mulberrytech dot com
- Subject: search and replace along with apply-templates
- From: Robert Koberg <rob at koberg dot com>
- Date: Sun, 19 Nov 2000 07:55:37 -0800
- Reply-To: xsl-list at mulberrytech dot com
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