[Yanel-dev] CDATA and comments problem

Evaldas Taroza etaroza at optaros.com
Wed Mar 5 09:06:07 CET 2008


Michael Wechner wrote:
> 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 &lt; 2){
>>   alert("OK");
>>  }
>> </script>
>>
>> This is illegal javascript. So it won't work. We change the initial 
>> script a bit:
>> <script>
>> &lt;!--
>>  if(1 < 2){
>>   alert("OK");
>>  }
>> //--&gt;
>> </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 guess it's a bug that either the I18nTransformer2 or the 
> XIncludeTransformer are stripping comments.

I haven't debugged that, but looks like it's one of them. However, I 
wouldn't call that a bug. In the world of XSLT transformers usually 
strip comments (allthough you can match it with comment() and copy it 
again).
But in this specific case it is really a problem, and since the two 
transformers are kind of "hidden" they should really do full copy of 
every node.

> 
> Have you debugged which transformer is actually stripping the comment?
> 
> As a workaround you might want to reference the Javascript <link .../> 
> or does it need to generated dynamically?

In some places I need to generate it dynamically. And I don't want to 
create *.js files for such small script snippets.

Evaldas

-- 
+41 79 616 53 76
www.linkedin.com/in/taroza

Optaros - www.optaros.com


More information about the Yanel-development mailing list