[Yanel-dev] CDATA and comments problem
Josias Thöny
josias.thoeny at wyona.com
Wed Mar 5 11:33:41 CET 2008
Evaldas Taroza wrote:
> Hi,
> I have a problem when trying to pipe an XML through jelly and XSLTs.
> consider a jelly which has a script tag:
> <script>
> if(1<2){
> alert("OK");
> }
> </script>
>
> This jelly won't work. So we change it into:
> <script>
> <![CDATA[
> if(1<2){
> alert("OK");
> }
> ]]>
> </script>
>
> After this passes the jelly engine I get:
> <script>
> if(1 < 2){
> alert("OK");
> }
> </script>
>
> This is illegal javascript. So it won't work.
Actually this might work in XHTML strict. But I guess it doesn't work in
any other flavor of (X)HTML.
Maybe the serializer should not escape the content of a script tag in
HTML transitional?
> We change the initial
> script a bit:
> <script>
> <!--
> if(1 < 2){
> alert("OK");
> }
> //-->
> </script>
>
> This passes the jelly fine and we get:
> <script>
> <!--
> if(1 < 2){
> alert("OK");
> }
> //-->
> </script>
>
> This script would work in html world. Now the problem that this output
> should also get through I18nTransformer2 and XIncludeTransformer of
> Yanel. So afterwards I get:
> <script>
>
> </script
I think it's not the transformers. It's the XMLReader which doesn't send
any comment events. I just found out we have to set the LexicalHandler
in addition to the ContentHandler in the XML pipeline. If I add the
following second line in BasicXMLResource, the comments are appear in
the output:
xmlReader.setContentHandler(xsltHandlers[0]);
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler",
xsltHandlers[0]);
>
> So how to pipe jelly->i18n->xinclude so that finally we could get a
> working (x)html.
The general recommendation is not to use inline javascript...
If you have to use it maybe you could use a workaround by defining some
functions in an external javascript:
function lessThan(x, y) {
return x < y;
}
and use this in your jelly:
if (lessThan(x, y)) {
alert('ok');
}
I know it's not nice...
josias
>
> Evaldas
>
--
Josias Thöny
Wyona - Open Source Content Management
http://www.wyona.com
More information about the Yanel-development
mailing list