NAME

Cindy - use unmodified XML or HTML documents as templates.

SYNOPSIS

use Cindy;

my $doc = get_html_doc('cindy.html');
my $data = get_xml_doc('cindy.xml');
my $descriptions = parse_cis('cindy.cjs');

my $out = inject($data, $doc, $descriptions);

print $out->toStringHTML();

DESCRIPTION

Cindy does Content INjection into XML and HTML documents. The positions for the modifications as well as for the data are identified by xpath expressions. These are kept in a seperate file called a Content Injection Sheet. The syntax of this CIS file remotely resembles CSS. The actions for content modification are those implemented by TAL.

CIS SYNTAX

The syntax for content injection sheets is pretty simple. In most cases it is

<source path> <action> <target path> ;

The source and target path are xpath expressions. The action describes how to move the data. The whitespace before the terminating ; is required, since xpath expressions may end with a colon. The xpath expressions must not contain whitespaces. If the syntax for an action is different this is documented with the action.

Everything form a ; to the end of the line is ignored and can be used for comments.

CIS ACTIONS

All source paths for actions other than repeat should locate one node. Otherwise only the first one is used. The action is executed for all target nodes.

All xpath expressions are matched before the actions are executed. The source nodes are not modified during the execution. Order of execution does matter. If a e.g. target node is omitted, an action that changes its content will not have any effect.

true()    omit-tag  <target> ;
<source>  content   <target> ;

So the above is not equvalent to the replace action.

content

All child nodes of the target node are replaced by child nodes of the source node. This means that the text of the source tag with all tags it contains replaces the content of the target tag.

replace

The child nodes of the source node replace the target node and all its content. THis means that the target tag including any content is replaced by the content of the subtag. This is equivalent to

<source>  content   <target> ;
true()    omit-tag  <target> ;

omit-tag

The source node is used as a condition. If it exists and if its text content evaluates to true the target node is replaced by its children. This means that if the source tag exists and its content is not '' or 0 the target tag is removed while its content remains.

attribute

The syntax has an additional field atname

<source>  content   <target> <atname> ;

that holds the name of the attribute. If the source node exists, its content replaces or sets the value of the atname attribute of the target node. If the source node does not exist the attribute atname is removed from the target node.

condition

The source node is used as a condition. If it exists and if its text content evaluates to true nothing is done. Otherwise the target node and its children are removed. This means that the target tag is removed if the source tage does not exist or contains '', 0 or 0.0 whileit is left untouched otherwise.

repeat

The repeat action is the CIS equivalent of a template engines loop. For each match of the source path the source node and the target node are used as root nodes for a sequence of actions. The syntax is

<source>  repeat   <target> {
  <actions>
} ;

AUTHOR

Joachim Zobel <jz-2008@heute-morgen.de>

SEE ALSO

See Cindy/Sheet.pm for the RecDescent grammar for content injection sheets.