Publishing

On this page you can find several examples for the publishing business. The XML documents proved for publishing issues are instances of the popular DocBook standard.

Download of the files

Download all files mentioned on this page or the files for each individual example:

Proving processing instructions

XML Schema and DTDs are not able to regulate the names of PIs. But the use of PIs makes only sense if the names of the PIs are documentated and standardised.

XML instance

The convention is that the name of a PI should start with the prefix "sqf_". The instance contains two PIs whose names do not start with "sqf_".

1 <?xml version="1.0" encoding="UTF-8"?>
2 <?xml-model href="quickFix6.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
3 <article xmlns="http://docbook.org/ns/docbook" version="5.0">
4 <info>
5 <title>XSLT introduction</title>
6 </info>
7 <sect1>
8 <title>XSLT introduction to the transformation language</title>
9 <para>This section shall serve as an introduction to the transformation language XSLT. As already shown in the previous sections, XSLT is essential for the practical work with <?sqf_together start?>XSL-FO<?sqf_together end?>. The following explanations shall help to introduce <?together start?>XSL-FO<?together end?> and to understand the examples and applications in the text. In order to gain a deeper understanding of XSLT with all its facets, the book "Web-Design mit XML“ ("Web design with XML") by Manfred Knobloch and Matthias Kopp is recommended. This book was also published in the xml.bibliothek series of the publishing company dpunkt-Verlag.</para>
10 </sect1>
11 </article>

Schematron Schema

The schema identifies these incorrectly named PIs:

1 <?xml version="1.0" encoding="UTF-8"?>
2 <schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
3 <pattern id="PIs">
4 <rule context="processing-instruction()">
5 <assert test="starts-with(name(),'sqf_')">The <name/> PI does not correspond to the name convention. The prefix "sqf_" is missing.</assert>
6 </rule>
7 </pattern>
8 </schema>

QuickFixes

5 <assert test="starts-with(name(),'sqf_')" sqf:fix="delete replace setName">The <name/> PI does not correspond to the name convention. The prefix "sqf_" is missing.</assert>
6 <sqf:fix id="delete">
7 <sqf:description>
8 <sqf:title>Delete the PI.</sqf:title>
9 </sqf:description>
10 <sqf:delete/>
11 </sqf:fix>
12 <sqf:fix id="setName">
13 <sqf:description>
14 <sqf:title>Set a new name for this PI.</sqf:title>
15 </sqf:description>
16 <sqf:user-entry name="newName">
17 <sqf:description>
18 <sqf:title>Enter the new name.</sqf:title>
19 </sqf:description>
20 </sqf:user-entry>
21 <sqf:replace target="{$newName}" node-type="pi">
22 <value-of select="."/>
23 </sqf:replace>
24 </sqf:fix>
25 <sqf:fix id="replace">
26 <sqf:description>
27 <sqf:title>Add the missing prefix.</sqf:title>
28 </sqf:description>
29 <sqf:replace target="sqf_{name()}" node-type="pi">
30 <value-of select="."/>
31 </sqf:replace>
32 </sqf:fix>
33 </rule>

There are three possible QuickFixes:

  • Delete the incorrectly named PI.

  • The user may set a new name.

  • Add the missing prefix.

See also

The Schematron QuickFix schema uses the following SQF elements:

Please read the reference in order to learn the functionality of these SQF elements.

Too many levels in a list

The DocBook standard allows unbounded hierachical levels in its list model. But each publication has a limit of list levels. This example deals with this problem:

XML instance

This list consists of four hierachical levels:

8 <title>Table of Contents</title>
9 <orderedlist>
10 <listitem>
11 <para>Introduction</para>
12 </listitem>
13 <listitem>
14 <para>Basics</para>
15 <orderedlist>
16 <listitem>
17 <para>Expression Context</para>
18 <orderedlist>
19 <listitem>
20 <para>Static Context</para>
   [...]
24 </listitem>
25 </orderedlist>
26 </listitem>
27 <listitem>
28 <para>Processing Model</para>
   [...]
35 </listitem>
36 <listitem>
37 <para>Expression Processing</para>
38 <orderedlist>
39 <listitem>
40 <para>Static Analysis Phase</para>
   [...]
44 </listitem>
45 </orderedlist>
   [...]
52 </listitem>
53 </orderedlist>
   [...]
125 </listitem>
126 </orderedlist>
127 </listitem>

Schematron schema

For the schema the convention was set that a list should have at the maximum two list levels:

1 <?xml version="1.0" encoding="UTF-8"?>
2 <schema xmlns="http://purl.oclc.org/dsdl/schematron" xmlns:db="http://docbook.org/ns/docbook" xmlns:es="http://www.escali.schematron-quickfix.com/" queryBinding="xslt2">
3 <es:default-namespace uri="http://docbook.org/ns/docbook"/>
4 <pattern>
5 <rule context="*[listitem]">
6 <let name="level" value="count(ancestor::listitem)+1"/>
7 <report test="$level >= 3">Too many levels in this list. We are in level <value-of select="$level"/>.</report>
8 </rule>
9 </pattern>
10 </schema>

QuickFixes

7 <report test="$level >= 3" sqf:fix="delete plain">Too many levels in this list. We are in level <value-of select="$level"/>.</report>
8 <sqf:fix id="delete">
9 <sqf:description>
10 <sqf:title>Delete this list.</sqf:title>
11 </sqf:description>
12 <sqf:delete/>
13 </sqf:fix>
14 <sqf:fix id="plain" use-when="not(.//*[listitem] or $level > 3)">
15 <sqf:description>
16 <sqf:title>Resolve the list into plain text.</sqf:title>
17 </sqf:description>
18 <sqf:replace match=".|.//*[listitem]">
19 <sqf:keep select="listitem/node()"/>
20 </sqf:replace>
21 </sqf:fix>

The QuickFixes only provide two options: deleting the sublist or resolving it into plain text. Unfortunately, sometimes there is no satisfactory fix.

See also

The Schematron QuickFix schema uses the following SQF elements:

Please read the reference in order to learn the functionality of these SQF elements.

Footnote in footnote

This Schematron example is already implemented in the DocBook standard. Footnotes as descendants of footnotes are forbidden. The validation of this restriction works with Schematron.

XML instance

The instance bellow contains such forbidden footnotes:

7 <sect1>
8 <title>XSLT introduction to the transformation language<footnote>
9 <para>by Manuel Montero Pineda, CEO<footnote>
10 <para>chief executive officer</para>
11 </footnote> of data2type GmbH</para>
12 </footnote></title>
13 <para>This section shall serve as an introduction to the transformation language XSLT. As already shown in the previous sections, XSLT is essential for the practical work with XSL-FO. The following explanations shall help to introduce XSL-FO and to understand the examples and applications in the text. In order to gain a deeper understanding of XSLT with all its facets, the book "Web-Design mit XML“<footnote>
14 <para>engl.: "Webdesign with XML"<footnote>
15 <para>Authors:</para>
16 <itemizedlist>
17 <listitem>
18 <para>Manfred Knobloch</para>
19 </listitem>
20 <listitem>
21 <para>Matthias Kopp</para>
22 </listitem>
23 </itemizedlist>
24 </footnote></para>

Schematron schema

The schema is a reconstruction of the Schematron schema which is included in the DocBook standard.

1 <?xml version="1.0" encoding="UTF-8"?>
2 <schema xmlns="http://purl.oclc.org/dsdl/schematron" xmlns:es="http://www.escali.schematron-quickfix.com/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" queryBinding="xslt2">
3 <es:default-namespace uri="http://docbook.org/ns/docbook"/>
4 <pattern>
5 <rule context="footnote">
6 <report test=".//footnote">Footnote in footnote is forbidden.</report>
7 </rule>
8 </pattern>
9 </schema>

QuickFixes

The schema is enriched with QuickFixes for forbidden footnotes.

6 <report test=".//footnote" sqf:fix="delete brackets parentBrackets">Footnote in footnote is forbidden.</report>
7 <sqf:fix id="delete">
8 <sqf:description>
9 <sqf:title>Delete all forbidden footnotes.</sqf:title>
10 </sqf:description>
11 <sqf:delete match=".//footnote"/>
12 </sqf:fix>
13 <sqf:fix id="brackets" use-when="not(.//footnote[count(*) > 1 or not(para)])">
14 <sqf:description>
15 <sqf:title>Resolve the forbidden footnotes as text in brackets.</sqf:title>
16 </sqf:description>
17 <sqf:replace match=".//footnote"> (<xsl:apply-templates select="./para/node()"/>) </sqf:replace>
18 </sqf:fix>
19 <sqf:fix id="parentBrackets" use-when="not(ancestor::footnote) and count(*)=1 and para">
20 <sqf:description>
21 <sqf:title>Resolve the surrounding footnote as text in brackets.</sqf:title>
22 </sqf:description>
23 <sqf:replace> (<xsl:apply-templates select="./para/node()"/>) </sqf:replace>
24 </sqf:fix>

The schema has three QuickFixes:

  1. The simplest fix is to delete all descendant footnotes.

  2. This fix transforms the forbidden footnotes into text encloded by brackets. The fix will only be available if there are only footnotes which contain exactly one paragraph.

    This fix uses the <xsl:apply-templates> element because the resolved footnotes could contain other footnotes which would be forbidden, too. So, a simple copy of the containing nodes would not be sufficient.

  3. The third QuickFix is similar to the second fix. But the resolved footnote is the footnote which contains the forbidden footnotes. The fix will only be available if the footnote itself is not a descendant of a footnote and if the footnote contains exactly one paragraph.

See also

The Schematron QuickFix schema uses the following SQF elements:

Please read the reference in order to learn the functionality of these SQF elements.

Misuse of characters

This example is based on a XML structure in the publishing field which is similar to the DocBook standard. It demonstrates the handling of misused characters to generate graphic objects.

XML instance

The instance contains form fields created by misused periods (full stop characters) and underscores:

1 <?xml version="1.0" encoding="UTF-8"?>
2 <?xml-model href="quickFix9.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
3 <root>
4 <info>
5 <title>Newsletter</title>
6 </info>
7 <section>
8 <title>Newsletter</title>
9 <para>If you want to be informed about changes in Schematron QuickFix, please fill out this form:</para>
10 <para>First name: ..........................</para>
11 <para>Second name: ...........................................</para>
12 <para>E-mail: _____________________@_____________________.___</para>
13 </section>
14 </root>

Schematron schema

The Schematron schema bellow identifies the misused characters.

1 <?xml version="1.0" encoding="UTF-8"?>
2 <schema xmlns="http://purl.oclc.org/dsdl/schematron" xmlns:sqf="http://www.schematron-quickfix.com/validator/process" queryBinding="xslt2">
3 <pattern>
4 <rule context="text()">
5 <report test="matches(.,'____')" role="error">Misuse of the underscore character? More than two in a row.</report>
6 <report test="matches(.,'\.\.\.\.')" see="http://www.data2type.de" icon="../../xmlData/website/in/images/sqf-logo-tiny.png">Misuse of the period character? More than two in a row.</report>
7 </rule>
8 </pattern>
9 </schema>

QuickFixes

5 <report test="matches(.,'____')" sqf:fix="autoStringReplace" role="error">Misuse of the underscore character? More than two in a row.</report>
6 <report test="matches(.,'\.\.\.\.')" sqf:fix="autoStringReplace" role="fatal">Misuse of the period character? More than two in a row.</report>
7 <sqf:fix id="autoStringReplace">
8 <sqf:description>
9 <sqf:title>The misused characters will be replaced by a &lt;form&gt; element. The "length" and the "type" attribute will be generated.</sqf:title>
10 </sqf:description>
11 <sqf:stringReplace match="." regex="(__(_)+)|(\.\.(\.)+)">
12 <form xmlns="" length="{string-length(.)}"
13 type="{if (matches(.,'_')) then ('line') else ('doted')}"/>
14 </sqf:stringReplace>
15 </sqf:fix>

This is a prime example for the functionality of the <sqf:stringReplace> element. The misused characters will be replaced by a <form> element. The type and the length will be calculated automatically.

See also

The Schematron QuickFix schema uses the following SQF elements:

Please read the reference in order to learn the functionality of these SQF elements.

© Copyright 2014-2017 Nico Kutscherauer

ImprintContactSitemap