Subject: Re: Generating XML(HTML) from script in IE5b2... From: "Oren Ben-Kiki" <oren@xxxxxxxxxxxxx> Date: Tue, 5 Jan 1999 20:38:23 +0200 |
Guy_Murphy@xxxxxxxxxx <Guy_Murphy@xxxxxxxxxx> wrote: >... Secondly, rather than expecting XSL to re-parse the result, why would I >expect it to parse the result at all? I'm not being sarcastic, being new to >all this, I might well be missing something. The script.... > > <xsl:script> > <![CDATA[ > function displayVert (node) { > var result = ''; > var text = node.text; > > for (var i = 0; i < text.length; i++) { > result += '<div>'+text.substr(i, 1)+'</div>'; > > } > > return result; > } > ]]> > </xsl:script> > >... is marked as CDATA, so the <> for the DIVs shouldn't get changed to >< > there... >From the working draft, 2.4.7: "... Thus <!CDATA[<]]> in the source document will be treated the same as < ..." In short, there is no way whatsoever to emit the character "<" from an XSL processor. The fact that it would be very _useful_ to be able to emit this character is besides the point :-) The thing is that in XML you are not allowed to specify a literal "<" outside a CDATA section. There's no such section in the output. There also isn't a way to force the use of such a section in the output - something like <xsl:cdata> which would wrap anything except for output XML elements and attributes. Anyway, even if there was such a thing, it wouldn't have helped - browsers choke on CDATA. On the other hand, HTML isn't XML and it does allow using "<" in SCRIPT elements, for example. Inside quoted strings it _requires_ the literal character to be used. BTW, it handles < correctly outside quoted strings, and this is very lucky for all of us, or most generated JavaScript code wouldn't work - consider your loop, for example. I think that the "official" position is that the browser "should" convert < to < on input even inside quoted strings inside SCRIPT elements, and that the fact it doesn't do so in your case is a bug (my opinion only! I have no connection at all to the powers-that-be). Anyway, it's the sort of technically correct positions which don't help us a bit in practice :-) You are lucky; can change your script to use String.fromCharCode(60) and String.fromCharCode(62) instead of using the literal characters. If, however, this string with "<" in it had come from the XML input tree and you needed to embed it into a JavaScript string in the output, you'd have a real problem. The only thing I can think of is to implement an expandXmlMarkupfunction in JavaScript and wrap it around the text. I'm trying to work my way around this in my application (performance would be horrible, for one thing), but it seems there's nothing else I can do. Now, if there was an element like the hypothetical <xsl:cdata>, but which did not emit the <![CDATA[ ... ]]> wrapper - call it <xsl:supress-xml-markup> - then we'd be able to do what we please, up to and including building an XML output tree character by character, or emitting RTF, or PDF, or JavaScript, or Java, or Tcl, or Perl, or Tex, or whatever... But it would be completely useless for emitting XML output, which is all what is covered by the current intent. Have fun, Oren Ben-Kiki XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Generating XML(HTML) from scrip, Guy_Murphy | Thread | selectSingleNode vs selectNodes, Éric Riblair |
Re: Generating XML(HTML) from scrip, Guy_Murphy | Date | Re: writing entity references., Andrew Bunner |
Month |