PWP: Problems with <script> tags

19 views
Skip to first unread message

joachim...@gmail.com

unread,
Dec 9, 2014, 2:19:35 PM12/9/14
to swi-p...@googlegroups.com
I am trying to migrate a small PHP project to PWP  to take advantage of Prolog in the webserver. I am using SWI-Prolog 6.6.6 on CentOS 6 or 7. I have encountered some missing but necessary features and several problems, especially with converting <script> tags by PWP:


Wrong playout of <script> content to the browser:

PWP/HTML code like <script> a < b </script> is emitted as:

 <script> a &lt; b </script>

wich cannot be processed anymore by HTML browsers. However, this appeared to be a bug in sgml_write.pl. I have noted Jan already has fixed it in GIT, so this problem is solved now.for me.


Passing Prolog variables to script (JavaScript) content:

In PWP a Prolog variable can be passed to HTML and XML e.g. by <div pwp:use="Var" pwp:tag="-" />.
But this is not possible to CDATA content, especially not to content of <script> and <style> tags which is a common use case in PHP/JavaScript. With the c(..)c notation where c is a delimiter defined as argument of pwp:att, Prolog variables can be substituted in attribute values..

I would like to suggest to apply this substitution mechanism also to CDATA content of <script> and <style> tags.

For example, a PWP code like

    <script pwp:att="$" dummy="Test $(X)$" type="text/javascript">
     
var i = 0; if (i < 10) { document.write("$(X)$ items.."); }
   
</script>

should be transformed to (assuming X = 0):

    <script dummy="Test 0" type="text/javascript">
      var i = 0; if (i < 10) { document.write("0 items.."); }
    </script>


Nested PWP files:

With a tag like <div pwp:use="'File'" pwp:how="xml-file" /> it is possible to include XML and text files to the transformed content, but PWP processing is not applied to included XML files. Therefore I suggest to add a new value "pwp-file" to get a similar behaviour as PHP's <?include File ?> statement, for example:

 <div pwp:ask="X=1" pwp:use="'hello2.pwp'" pwp:how="pwp-file" />

When loading a nested PWP file, the current context (list of name=Value pairs) should be applied to it.
For example, if file "hello2.pwp" contains the following tag

<span pwp:use="X" pwp:tag='-'/>. hello

it should be transformed to "2. hello".


Implementation of my suggestions is straight-forward and no problem (I am going to submit a patch for pwp.pl).
Do you think my suggestions are useful for SWI-Prolog users and don't break existing code?






Reply all
Reply to author
Forward
0 new messages