Processing Instructions

PI's look as as the xml declaration

<?xml version='1.0' encoding='UTF-8'?>

User defined processing instructions PI's can be inserted in XML that look as:

<?Hello?>

The program processing the XML code as xslproc ignores them except when it is advised to do something with it. A match attribute needs to be added in a stylesheet to do something:

<xsl:template match="processing-instruction('Hello')">
The Processing Instruction says Hello
</xsl:template>

Instead of processing the PI the PI can also be created using a sylesheet with

<xsl:processing-instruction
name="Hello">
  <!-- -->
</xsl:processing-instruction> 

PI templates are available as for Docbook PI at http://docbook.sourceforge.net/release/xsl/current/doc/pi/index.html.

A good an useful example of an PI is to insert a date to an docbook file when it is processed to get html (or other formats as pdf). The PI would look:

<copyright>
      <year><?dbtimestamp format="Y"?> </year>
      <holder>www.linurs.org</holder>
</copyright>

or getting a time stamp

<?dbtimestamp format="Y-m-d H:M:S"?>

PI's are used by FOP to help formatting in the case the result of the automatic formatting of the stylesheets is in some places not what you like. If this is generally not what you like you should fix this in the stylesheet and do not use PI's:

Telling FO to not insert a page break in the following, to e.g. not split a table

<?dbfo keep-together="auto" ?>

Or force a so called soft page break with:

<?dbfo-need height="2in" ?>

Or a hard break

<?hard-pagebreak?>

Or add some vertical space

<?dbfo-need  height="0.5in"  space-before="3em" ?>

Add a background color

<?dbfo bgcolor="#<rrggbb>" ?>

Adding php code

<?php
  <some code>
?>

There are other examples as telling xlsproc what stylesheet to use. This is quite often used on web server where the web server makes makes the xslt on demand. If you have xml data that is alive and changes often then this is a good approach. But this violates the rule, write it once use it everywhere since at least for static xml you would like sooner or later apply different stylesheets:

<?xml-stylesheet type="text/xsl" href="<my stylesheet>.xsl"?>

Processing instructions PI can be inserted into XML as to force a file name of a html chunk:

<?dbhtml filename="intro.html" ?>

Or the subdir where the chunk goes:

<?dbhtml dir="sub" ?>

Or including html code from an other file

<?dbhtml-include href="mycode.html"?>

Linurs startpage