[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Wrong Characters Returned from Javascript Function
Larry, xsl escapes href attributes when the output method is html. So to fix this change the output method to xml or use onclick instead of href Ciao Chris XML/XSL Portal http://www.bayes.co.uk/xml >-----Original Message----- >From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx >[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Larry Davis >Sent: 31 May 2001 22:47 >To: David Specht; 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx' >Subject: 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 > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|