A processing instruction is a means of passing hints to the XSLT processor about how to handle something. XML permits the placement of processing instructions just about anywhere in a document. A processing instruction (sometimes referred to as a PI) uses a special syntax,
<?, to indicate that it is not an element, comment, or text. For example:
<?dbfo bgcolor="#EEEEEE" ?>
The first word in a PI is the name. In this example, the name of the processing instruction is
dbfo and the content is
bgcolor="#EEEEEE". This style of PI content could be called a “pseudo attribute”, because it provides a name-value pair similar to a real attribute (which only elements can have). You can put several such pseudo attributes in one PI, or you can put each of them in their own PI.
The DocBook stylesheets accept certain predefined processing instructions to specify information for which no DocBook element or attribute exists. In this example, it specifies the background color for a table cell, as described in the section “Cell background color”. DocBook processing instructions use the naming convention
dbhtml to mean processing instructions intended for the HTML stylesheets, and
dbfo for those PIs intended for the FO stylesheets. See the index for a list of predefined PIs of each type.
You can add your own processing instructions as part of your customization. If you use the DocBook PI name (
dbfo) and the pseudo attribute style of content, then you can use some of the stylesheet machinery to parse the content. Here is an example of how the DocBook stylesheet gets the value of the above example:
Example 8.3. Custom processing instruction
<xsl:variable name="backgroundcolor"> <xsl:call-template name="dbfo-attribute"> <xsl:with-param name="pis" select="ancestor-or-self::entry/processing-instruction('dbfo')"/> <xsl:with-param name="attribute" select="'bgcolor'"/> </xsl:call-template> </xsl:variable>
Put the selected value into a stylesheet variable named
Call the template named
The above selection step could get several PIs, each of which could have several pseudo attributes. The
To create processing instructions of your own, you need to do the following:
Decide on the names and possible values for your pseudo attributes.
Decide where you might place your processing instructions in your document.
For the elements that will contains such PIs, you will want to customize that element's template to make use of the PI.
Add XSL code similar to the above example to the customized template, changing the
select statement in the
pis parameter, and changing the value of the
attribute parameter to match your usage.
|DocBook XSL: The Complete Guide - 3rd Edition||PDF version available|
Copyright © 2002-2005 Sagehill Enterprises