cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ulrich Mayring <u...@denic.de>
Subject Re: permit quoting
Date Wed, 26 Jul 2000 16:28:27 GMT
tcurdt@dff.st wrote:
> 
> > > > > I need a '>' in there that does not belong to a XML tag!
> > > >
> > > > &gt;
> > >
> > > Of course I tried that, too...
> > >
> > > <![CDATA[ &gt;/tr&lt; &gt;tr&lt; ]]>
> > >
> > > ..should give me </tr> <tr> then, right?!
> > >
> > > But I get:
> > >
> > > &amp;gt;/tr&amp;lt; &amp;gt;tr&amp;lt;
> > >
> > > Now what?
> >
> > I told you it is really not worth it generating non-XML with XSLT :)
> 
> > You can hack around it time and time again, but in the long run you
> > won't get anywhere. So do yourself a favor and design your stuff in an
> > XML-way :)
> 
> I definitly will ...but... Sorry, I'm very insistant just to get
> everything right :-)
> 
> > Anyway, as I said before, don't use XML in a CDATA section and don't use
> > non-XML outside it. If you want to generate a mixture, then open and
> > close CDATA sections as needed.
> 
> Well, the problem is the '<' is non-valid in XML but does not get
> passed in the CDATA section - as far as I can see.
> 
> <![CDATA[ </tr> if(a>b) ]]>
> <![CDATA[ &gt;/tr&lt; if(a&gt;b) ]]>
> &gt;<![CDATA[/tr]]>&lt;<![CDATA[if(a]]>&gt;<![CDATA[b) ]]>
> 
> These are all possibilities I can think of... have I forgotten
> one? Now please show me -am I too stupid?- how you want to make
> this javascript expression work! It needs the '<' operator!
> Because all I get is:
> 
> &lt;/tr&gt; if(a&gt;b)
> &gt;/tr&lt;if(a&gt;b)
> How? Would you make this work - how messy it might be...

Well, I am not going to debug your code, but I am going to tell you how
to write good code, that is even better :)

You have to re-write your code first and then worry about getting it
into an XSLT stylesheet. These are the principles for rewriting your
code:

- HTML and XML are the same thing for XSLT. Whenever I say XML I also
mean things like <tr> </tr>, which are later interpreted as HTML. But
XSLT doesn't know about HTML, it interprets these tags as XML.
- You should put Javascript in a CDATA section, nowhere else.
- You should put XML outside of a CDATA section, nowhere else. (You are
not doing that above).
- Do not do your logic in JavaScript. You have cocoon to do the logic.
- Use JavaScript for HTML-like things like rollover animations of
buttons and such.

Here is how I generate Javascript, that should show you how to solve
your problem:

<xsl:template name="generate-javascript">
<script language="javascript" type="text/javascript">
	<![CDATA[
	<!--//
	function PreloadImages(length, path, type) {
	for(var i = 1; i<=length; i++)
		{
		this[i] = new Image()
		this[i].src = path + i + type
		}
	return this
	}

	mouseover=new PreloadImages(6,']]>
		<xsl:value-of select="$img"/>
	<![CDATA[/mouseover/]]>
		<xsl:value-of select="$interfix"/>
	<![CDATA[/button','.gif')
	...
	//-->
	]]>
</script>
</xsl:template>

As you can see I am using a '<' character in my JavaScript and whenever
I need to do logic, I just close the CDATA section temporarily and use
XSLT. If you keep XML and non-XML cleanly seperated, then the code
remains halfway readable. It might even work, too ;-)

But XML tags have no business inside of a CDATA section.

BTW, remember to write stuff like the mouseover thing above in one line
to kill extra whitespace. I just put it on multiple lines to make it
easier to read for you.

Ulrich

-- 
Ulrich Mayring
DENIC eG, Systementwicklung

Mime
View raw message