Conditional Processing

Shaun McCance <shaunm at gnome.org>
Sat Mar 6 22:10:08 EST 2010

Hi folks,

I'd like to talk about how (and if) we should support
conditional processing in Mallard.  A few people have
requested this, and it's not out of the question to
get it into 1.0.

For background, both DocBook and DITA take basically
the same approach.  Elements can have attributes that
specify certain things that element is effective for.
So you have things like these

<para arch="...">
<p platform="...">

When you hand your document to a processing tool, you
tell the tool what sorts of things you want to filter
on.  If you don't explicitly filter on e.g. platform,
those attributes don't do anything.

(This is all my general understanding.  Please correct
me if I'm wrong.)

A problem with using this approach in Mallard is that
Mallard is used as a deliverable format, so processing
time is display time.  You don't have the chance to tell
your processing tool which filters to apply.

As an example, suppose you had a paragraph that you only
want shown in Ubuntu, and another you only want shown in
every other distro.  In DocBook (pre-processing, not on
the fly in Yelp), you might do something like this:

<para condition="ubuntu">Some Ubuntu stuff</para>
<para condition="notubuntu">Some other stuff</para>

You would do two builds, the first one requiring ubuntu
in condition, and the other requiring notubuntu.

So we could go down the road of defining a syntax for
basic boolean combinations, and get stuff like this:

<p distro="ubuntu">Ubuntu rocks!</p>
<p distro="fedora">Fedora rocks!</p>
<p distro="!(ubuntu || fedora)">My distro rocks!</p>

But I don't want to write a parser, especially not in
XSLT.  So I propose we just use XPath 1.  It's available
in just about any XML processing tool.  And instead of
separate conditional attributes, where we have to decide
whether they OR or AND together, we can just have a single
attribute.  Then we define some extension functions to get
certain data.

<p if="mal:key('distro') = 'fedora'">Fedora rocks!</p>

This is really dead simple to implement in XSLT as long
as your processor supports these EXSLT extensions:

http://www.exslt.org/dyn/functions/evaluate/index.html
http://www.exslt.org/func/elements/function/index.html

If this is an approach people like, we'd have to decide
which functions and types of data to specify.  Mallard
extensions (and future versions) can always add things
to this (which is something I really like about this
approach).  But I do not want conditional processing
to go in without a very clear specification, because
authors need to know that their documents will work in
different environments.

Thoughts?

-- 
Shaun McCance
http://syllogist.net/