Subject: Re: [xsl] Escaping apostrophes for use in javascript, etc. - how to trouble shoot template results? From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 9 Oct 2003 15:14:30 +0100 |
Hi Kathy, > I'm using a stylesheet whose output includes some javascript > (typical stuff, validation, submit, etc.) run exclusively in IE6 > using msxml4. One of the functions includes a parameter whose text > can contain apostophes. > > function Anomaly(typeIn,idIn,textIn) > newWindow = > window.open(('Anomaly.aspx?type='+typeIn+'&id='+idIn+'&text='+textIn), > 'Anomaly', 'width=650,height=700'); > > This passes certain text nodes as parameters, which then get > included in the querystring to the next form. Presumably you're generating this JavaScript using XSLT? Can you show us the XSLT that you're using to generate it? > Trying to solve this, I included a template written by Jeni Tennison > (from an online post) to escape apostrophes. In the variable > name="apos" the select='"'"' -- I don't understand how/if this > is working. Does xsl look for the actual ' character? Yes. When an XML document (the XSLT stylesheet in this case) is parsed, the entity reference ' is replaced by an apostrophe and this value is passed to the application (the XSLT processor in this case). As far as the XSLT processor is concerned, the value of the select attribute is "'", which is a legal XPath expression consisting of a single string literal (delimited by "s) whose value is a string containing a single apostrophe character. The template searches for an apostrophe within the string and replaces all occurrences with the two characters \'. > And how would one tell if it's working...I know I wouldn't see a > backslash appear with the apostrophe in the html output > transformation, but how do I check if this is working? Um, well, if you're using the template in the way that it's designed to be used (which is to escape strings that are then output in the result of the stylesheet), then you should see a backslash appear with the apostrophe in the source HTML output of the XSLT stylesheet. You say that you're using Xselerator? In the Output Window, choose the "View output as text" option and look at the JavaScript. I'm not actually sure what problem you're encountering. Are you getting a JavaScript error when you view the page? What does it say? The usual advice when generating HTML applies: first create an HTML page that works, containing the JavaScript that works, and then create that HTML page using XSLT. That way you can separate problems with the JavaScript from problems with the XSLT. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Escaping apostrophes for use , Kathy Burke | Thread | [xsl] Escaping apostrophes for use , Kathy Burke |
[xsl] Re: [xsl] Problems transformi, andrew . curry | Date | Re: [xsl] Muenchian grouping help -, Mukul Gandhi |
Month |