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]

Wrong Characters Returned from Javascript Function


I have a JavaScript function that cleans apostrophes and quotation marks
from text as it is written as a parameter into another JavaScript function
on an html page.  The JavaScript function returns different symbols for the
copyright and trademark symbols.  I tried commenting out all the processes
inside escapeApos() function.  Even when I return the exact same string, the
characters are altered. There is an example of the output below.

We are using MSXML3 for transformation.

Any help would be appreciated.   

Thanks, Larry


XSL Code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="user"
exclude-result-prefixes="msxsl user">
	<xsl:output method="html" version="4.0" omit-xml-declaration="yes"
indent="no" media-type="text/html" encoding="UTF-16"/>
	<msxsl:script language="JavaScript" implements-prefix="user">
			<![CDATA[function escapeApos(str_in) {
							var char1 = /'/gi;
//Chr(39)
							var char2 = /"/gi;
//Chr(34)
							str_in =
str_in.replace(char1, "\\'");
							str_in =
str_in.replace(char2, "\\'");
							return str_in;
			}]]>
</msxsl:script>
	<xsl:template match="/Items">
		<xsl:apply-templates select="Item"/>
	</xsl:template>
	<xsl:template match="Item">
		<P/>
		<a>
			<!--Write variables into html stream for javasccript
function -->
			<xsl:attribute
name="href">javascript:editItem(<xsl:value-of select="ItemID"/>,
'<xsl:value-of select="user:escapeApos(string(ItemShortDesc))"/> ')
</xsl:attribute>Edit This Item</a>
	</xsl:template>
</xsl:stylesheet>


XML Example:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="AposTest.xsl"?>
<Items>
	<Item>
		<ItemID>123</ItemID>
		<ItemShortDesc>Grimm's Fairy Tales ®</ItemShortDesc>
	</Item>
	<Item>
		<ItemID>123</ItemID>
		<ItemShortDesc>Bob's Fairy Tales ®</ItemShortDesc>
	</Item>
	<Item>
		<ItemID>123</ItemID>
		<ItemShortDesc>Roger's Fairy Tales ®</ItemShortDesc>
	</Item>
</Items>

XSL Returns:
<P></P>
<a href="javascript:editItem(123, 'Grimm\'s Fairy Tales %C2%AE ') ">Edit
This Item</a>
<P></P>
<a href="javascript:editItem(123, 'Bob\'s Fairy Tales %C2%AE ') ">Edit This
Item</a>
<P></P>
<a href="javascript:editItem(123, 'Roger\'s Fairy Tales %C2%AE ') ">Edit
This Item</a>

 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]