next up previous
Next: Specific Structures Up: Handling HTML as Prolog Previous: Handling HTML as Prolog

General Structures

 

Basically, HTML has two kinds of components: HTML elements and HTML environments. An HTML element has the form `` <NAME Attributes >'' were NAME is the name of the element and Attributes is a (possibly empty) sequence of attributes, each of them being either an attribute name or an attribute assignment as name="Value".

An HTML environment has the form ``<NAME Attributes > Text </NAME>'' were NAME is the name of the environment an Attributes has the same form as before.

The general Prolog structures that represent these two HTML constructions are:

Now we can rewrite the previous example as follows:

#!/usr/local/bin/lpshell

:- use_module('/usr/local/src/pillow/pillow.pl').

main(_) :-
    get_form_input(Input),
    get_form_value(Input,person_name,Name),
    response(Name,Response),
    output_html([
        'Content-type: text/html',
        html([title('Telephone database'),
              img$[src='phone.gif'],
              h2('Telephone database'),
              hr$[],
              Response)]).

response(Name, Response) :-
    form_empty_value(Name) ->
       Response = 'You have to provide a name.'
  ; phone(Name, Phone) ->
       Response = ['Telephone number of ',b(Name),': ',Phone]
  ; Response = ['No telephone number available for ',b(Name),'.'].

phone(daniel, '336-7448').
phone(manuel, '336-7435').
phone(sacha,  '543-5316').

Any HTML construction can be represented with these structures (except comments and declarations, which could be included as atoms or strings), but the PiLLoW library provides additional, specific structures to simplify HTML creation.


next up previous
Next: Specific Structures Up: Handling HTML as Prolog Previous: Handling HTML as Prolog

Daniel Cabeza Gras
Fri Oct 4 18:56:02 MET DST 1996