Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 6 ■ DOCUMENTATION AND CODING CONVENTIONS^65

At this point, you have some HTML output, but it’s all in one file, which may not be ideal.
To break apart the file, say by chapter, you will need to create your own XSL file. This can be
exceedingly complicated or fairly easy, depending on how fancy you want to get with the output.
The stylesheet in Listing 6-4 demonstrates how to import the chunk.xsl stylesheet from the
SourceForge DocBook project (http://docbook.sourceforge.net). Save this file as yourfile.xsl.

Listing 6-4. A Chunking DocBook Custom XSL Stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">

<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/ ➥
chunk.xsl"/>
<xsl:param name="use.id.as.filename">1</xsl:param>
</xsl:stylesheet>

Next, you will need to add id attributes to your DocBook file, as shown in Listing 6-5.

Listing 6-5. DocBook File with id Attributes Applied

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"/usr/share/xml/docbook/schema/dtd/4.4/docbookx.dtd">

<book id="mybook">

<bookinfo>
<title>Documentation</title>
<subtitle>Cool Application</subtitle>
</bookinfo>

<chapter id="mychapter">
<title>Chapter Title</title>
<sect1 id="firstsection">
<title>Section Title</title>
<para>Introduction to this section</para>
<sect2 id="subsection">
<para>Sections may have subsections</para>
</sect2>
</sect1>
</chapter>

</book>

Finally, use yourfile.xsl instead of the docbook.xsl with the xsltproc command, like so:

xsltproc yourfile.xsl yourfile.xml

McArthur_819-9C06.fm Page 65 Friday, February 22, 2008 8:59 AM

Free download pdf