At 2:42 PM -0400 10/10/02, Eric S. Raymond wrote:
I knew something bothered me about this, and the problem just smacked me upside the head:Here's my tutorial example:Preamble <!-- this is the test on the manual page --> Always issue this text. <?if condition='html'> Issue this text if 'condition=html' is given on the command line. <?elif condition='pdf|ps'> Issue this text if 'condition=pdf' or 'condition=ps' is given on the command line. <?else> Otherwise issue this text. <?fi> Always issue this text. <!-- this ends the test on the manual page --> <?if condition='foo'> Should display only if condition is foo <?elif condition='baz'> Should display only if condition is baz <?else> Should display only if condition is not foo and not baz <?fi> <?if not condition='bar'> Should display only if condition is not bar <?if cond2='on'> This should be displayed only when cond2 is on. <?fi> <?else> Should display only if condition is bar <?fi> Postamble.
An XSLT processor operates a on a tree of nodes, but
processing instructions cross tree boundaries.
In other words, a single processing instruction in one place is OK. However, a begin-end pair is not. That needs to be an element. Otherwise, we're stuck with the possibility of this:
<section>
<para>
<?if cond2='on'>
This should be displayed only when cond2 is on.
</para>
But wait! We just eliminated the end-tag!
<?fi>
<?else>
We could sneak an end-tag in here, but do we really want to
rely on this?
<?fi>
</section>
Is this fixable? Not with PIs. I think if you really need overlapping markup, you need to look at something other than XML. However, maybe it could be fixed by using attributes rather than PIs. For example,
<section xmlns:cnd="http://www.example.org">
<para cnd:if='on'>
This should be displayed only when cond2 is on.
</para>
</section>
I can't work an else into this scheme though. If you really want to do this, I think it needs to be done with elements, not processing instructions. It would take a preprocessor step to convert it to valid, transformable XML.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | [EMAIL PROTECTED] | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| Processing XML with Java (Addison-Wesley, 2002) |
| http://www.cafeconleche.org/books/xmljava |
| http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+