Edgewall Software

Comparing Genshi to Kid

The XML-based template engine in Genshi was heavily inspired by Kid (http://kid-templating.org).

Common concepts and features:

  • The same basic set of directives (excluding py:extends and py:layout)
  • Inline expressions using the ${expr} (or just $expr) syntax.
  • Expressions are real Python code, not some “crippled” mini language.
  • Stream-based processing model making heavy use of Python generators.
  • Different serialization methods, for example to produce XML or HTML output.

Differences include:

  • No generation of Python code for a template; the template is executed directly.
  • Expressions are evaluated in a more flexible manner, meaning you can use e.g. dotted notation to access items in a dictionary, and the other way around (see the genshi.template.eval module)
  • Proper scoping of variables. Names do not leak into outer scopes.
  • Use of XInclude and match templates instead of Kid's py:extends / py:layout directives
  • py:match directives use (basic) XPath expressions to match against input nodes, making match templates more powerful while keeping the syntax simple (see Using XPath in Genshi)
  • Additional directives py:choose / py:when / py:otherwise to better support multi-branch conditionals (aka if, else if, else).
  • It is possible to include markup that is not well-formed in the output (which you may need to do in some cases). And if you need to include bad HTML markup but would like to still produce valid output, Genshi provides a HTML-sanitizing stream filter.
  • Real (thread-safe) search path support
  • No dependency on ElementTree (due to the lack of position reporting)
  • The original location of parse events is kept throughout the processing pipeline, so that errors can be tracked back to a specific line/column in the template file

Other minor syntactic changes (useful when converting):

  • The XML Namespace used is http://genshi.edgewall.org/, not http://purl.org/kid/ns#
  • py:attrs takes a dictionary argument or list of tuples but doesn't support keyword arguments in the form name=value

See also: GenshiFaq, GenshiPerformance, Documentation

Last modified 17 years ago Last modified on May 3, 2007, 1:08:25 AM