XML technologies / Schematron / Schematron cookbook / Publishing
(Excerpt from "Schematron - Effiziente Business Rules für XML-Dokumente", chapter 8)
XML documents for print publishing
XML typesetting can reveal structural and content inconsistencies. Established recursive formats such as DocBook or DITA can cause many conflicts with print’s limited display area.
The following DocBook instance contains several such problems.
DocBook instance
<article xmlns="http://docbook.org/ns/docbook" version="5.0">
<info>
<title>XSL-Funktionen</title>
</info>
<sect1>
<title>XSL-Funktionen</title>
<para>Dieses Kapitel beschäftigt sich mit den wichtigsten XSL-Funktionen, ungeachtet, ob es sich dabei um XSLT- oder <?zusammenhalten start?> XPath-Funktionen <?zusammenhalten end?> handelt. Im Referenz-Teil befinden sich jeweils kurze Beschreibungen zu sämtlichen XSL-Funktionen. Hier werden wir lediglich auf jene Funktionen näher und mit beispielhaften Anwendungen eingehen, die in <?d2t_zusammenhalten anfang?> XSL-FO <?d2t_zusammenhalten ende?> Stylesheets typischerweise und häufig benutzt werden.<footnote>
<para>Vgl. Montero, Manuel, "Professionelle XML-Verarbeitung mit Word: WordML und SmartDocuments"<footnote>
<para>Erschienen beim dpunkt.verlag.</para>
</footnote></para>
</footnote></para>
<para>Um einen ersten Überblick zu geben, welche Funktionen welcher Recommendation zuzuordnen sind, folgt hier eine Liste sämtlicher Funktionen:</para>
<para>Zu XPath gehören thematisch geordnet:</para>
<itemizedlist>
<listitem>
<para>XPATH 1.0</para>
<itemizedlist>
<listitem>
<para>Knotenmengen-Funktionen:</para>
<itemizedlist>
<listitem>
<para>Zählfunktionen:</para>
<itemizedlist>
<listitem>
<para>count()</para>
</listitem>
<listitem>
<para>last()</para>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
<para>Bitte tragen Sie hier Ihren Namen ein: _________</para>
</sect1>
</article>Checking processing instructions
Professional XML publishing often needs instructions embedded in documents to control page layout. XML provides processing instructions (PIs) for this purpose. For example, the following PI might prohibit line breaks from <?zusammenhalten start?> through <?zusammenhalten end?>. When different people edit documents over years, publishers should standardize these instructions and document correct PI use. The following Schematron-pattern defines “correct” PI use by checking that each has the prefix d2t_ prepended.
<pattern id="PIs">
<rule context="processing-instruction()">
<assert test="starts-with(name(),'d2t_')">Diese PI stammt nicht von data2type, bitte dokumentieren Sie Ihre Funktion. Name der PI: <value-of select="name()"/></assert>
</rule>
</pattern>Typesetting difficulties
Unlike web pages, printed pages have fixed geometric bounds for layout and content. Media-neutral XML often does not encode output-channel constraints, causing conflicts with those bounds. Here are two examples.
XML lists are usually recursive: list items may contain further lists.
<itemizedlist>
<listitem>
<para>Zählfunktionen:</para>
<itemizedlist>
<listitem>
<para>count()</para>Nesting creates a hierarchy. Paragraph <para>Zählfunktionen:</para> is at level one, paragraph <para>count()</para> at level two.
Depending on page area and indentation, only a limited number of list levels fit on paper or remain typographically acceptable.
This Schematron pattern therefore reports an error for lists nested deeper than two levels:
<pattern id="Listen">
<rule context="db:listitem">
<report test="count(ancestor::db:listitem) > 2"> Eine Liste darf nicht mehr als drei Ebenen haben. Wir sind in der <value-of select="count(ancestor::db:listitem)+1"/>. Ebene.</report>
</rule>
</pattern>Another example is footnotes. Footnotes are inline elements allowed in all blocks, such as paragraphs, list items, cells and headings. They themselves contain blocks, permitting recursion. A footnote can contain a table containing another footnote, often unsuitable for print.
The following pattern prevents nested footnotes:
<pattern id="Fussnoten">
<rule context="db:footnote">
<report test=".//db:footnote">Eine Fußnote darf sich nicht in einer Fußnote befinden.</report>
</rule>
</pattern>Character usage
Schematron checks strings as well as structures. Document-centric data can contain many inconsistencies. For example, a paragraph may use repeated underscores to draw a line.
<para>Bitte tragen Sie hier Ihren Namen ein: _________</para>
Characters used as graphics can cause serious display errors depending on context and medium; line or page breaks might split the underscores.
This pattern checks for more than three consecutive underscores, likely “character abuse”.
<pattern id="Zeichen">
<rule context="text()">
<report test="contains(.,'____')"> Mehr als drei Unterstriche hintereinander. Ein Missbrauch kann nicht ausgeschlossen werden.</report>
</rule>
</pattern>Function contains() checks each text node for more than four consecutive underscores.
Copyright © dpunkt.verlag GmbH 2011
You may print the online version for private use. Otherwise, this chapter from "Schematron - Effiziente Business Rules für XML-Dokumente" is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, phone 06221-14830, fax 06221-148399, hallo(at)dpunkt.de