Subject: Re: JavaScript problems in my XSL file From: Mike Brown <mike@xxxxxxxx> Date: Fri, 3 Nov 2000 20:14:51 -0700 (MST) |
Ken Dickerson wrote: > I have an XSL file that I use to display my XML data. The XSL file contains > some JavaScript. I have not been having troubles using JavaScript within the > XML file until I added a for loop. The for loop loops like: for (i=0; i<6; > i++)... When I try to load my pages, I get an error at the 6. I believe the > error is that XSL is trying to create a tag from the lessthan sign. How can > I get XSL to understand that this is code and not some tagging? I am using > the namespace "http://www.w3.org/1999/XSL/Transform". I have defined my > script block with LANGUAGE="JavaScript" inside the HEAD block which is > inside the <xsl:template match="/"> block. > > I have gotten it to work when I replace the < sign with < which is pretty > ugly! Ugliness aside, it is absolutely correct. You don't have the option of making your XSLT be malformed XML. So you *must* escape it, or use a <![CDATA[ ... ]]> section, which serves no purpose but to make it so you don't have to escape the text in that section. This escaping is input-side only; it has no bearing on what the character data actually means, nor on the output after XSLT processing. Having unescaped markup characters in 'script data' type elements in HTML is an option offered by HTML for the convenience of document authors -- the 'natural' way is to escape every markup character that's not being used as markup. HTML is nice about it and says that unescaped markup character in certain elements is required to be treated exactly the same as an escaped markup character. That's why you can get away with not escaping it. A stylesheet is not a literal specification for output. Escape the not-being-used-as-markup markup characters on the way in, and let the processor escape them on the way back out. Internally, they aren't escaped at all, but you wouldn't know that by looking at just the input and output. If you feel that the text nodes your stylesheet is creating must be serialized without markup characters being escaped (which could create malformed output, if you think about it), then you have the option of using the disable-output-escaping="yes" attribute on xsl:value-of or xsl:text instructions that create the text nodes. I would not worry about it, though. Browsers are required to handle escaped script data. - Mike ____________________________________________________________________ Mike J. Brown, software engineer at My XML/XSL resources: webb.net in Denver, Colorado, USA http://www.skew.org/xml/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
JavaScript problems in my XSL file, Ken Dickerson | Thread | Re: JavaScript problems in my XSL f, Perry Molendijk |
Re: XML generated from a servlet, Rob Jagelski | Date | Re: apply-templates iside for-each?, Mike Brown |
Month |