个人工具

“UbuntuHelp:DocBook”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/DocBook}}
 
{{From|https://help.ubuntu.com/community/DocBook}}
 
{{Languages|UbuntuHelp:DocBook}}
 
{{Languages|UbuntuHelp:DocBook}}
 
 
=== Purpose ===
 
=== Purpose ===
 
 
The purpose of this page is to give an overview of the DocBook format. It offers an explanation of the advantages of this format, links further reading on this subject and contains a short tutorial.
 
The purpose of this page is to give an overview of the DocBook format. It offers an explanation of the advantages of this format, links further reading on this subject and contains a short tutorial.
 
 
=== What is DocBook? ===
 
=== What is DocBook? ===
 
DocBook is an XML based standard, which is used in many of todays documentation tasks. Practically speaking, when you want to create a DocBook document source, you write XML files which describe the documents layout, paragraph division and other attributes. XML file structure may look familiar to you if you have seen HTML code before. XML tends to be an improvment over the older HTML specification and can be used to produce complete web pages and other markup documents.
 
DocBook is an XML based standard, which is used in many of todays documentation tasks. Practically speaking, when you want to create a DocBook document source, you write XML files which describe the documents layout, paragraph division and other attributes. XML file structure may look familiar to you if you have seen HTML code before. XML tends to be an improvment over the older HTML specification and can be used to produce complete web pages and other markup documents.
 
 
=== What are the Advantages of Docbook? ===
 
=== What are the Advantages of Docbook? ===
 
Docbook is an OASIS standard and the format in which most open source projects store their documentation. Docbook is developed as an open source application. The project is hosted at Source''''''Forge and is made available under the GPL. Docbook is available as a Document Type Definition (DTD) and XML Schema (XSD). The project has a large developer and support community spanning both open source and commercial groups.
 
Docbook is an OASIS standard and the format in which most open source projects store their documentation. Docbook is developed as an open source application. The project is hosted at Source''''''Forge and is made available under the GPL. Docbook is available as a Document Type Definition (DTD) and XML Schema (XSD). The project has a large developer and support community spanning both open source and commercial groups.
 
 
The most important reasons why the project uses Docbook include:
 
The most important reasons why the project uses Docbook include:
 
+
# Docbook is a standard
* Docbook is a standard
+
# Docbook is open source
* Docbook is open source
+
# Docbook is used by most major projects
* Docbook is used by most major projects
+
# Docbook has a large developer and support community
* Docbook has a large developer and support community
+
 
+
 
Docbook is also an XML application and XML technologies solve a number of publishing problems for documentation teams, including:
 
Docbook is also an XML application and XML technologies solve a number of publishing problems for documentation teams, including:
 
+
* Single-sourcing
*** Single-sourcing
+
* Collaborative authoring
*** Collaborative authoring
+
* Cross-platform editing
*** Cross-platform editing
+
* Multi-channel publishing
*** Multi-channel publishing
+
* Improving information quality and consistency
*** Improving information quality and consistency
+
* Enhancing functionality of electronic output
*** Enhancing functionality of electronic output
+
* Negating vendor lock-in
*** Negating vendor lock-in
+
 
+
 
More information on these points can be found at http://www.sastc.org.za/articles/xml-solv-prop.html
 
More information on these points can be found at http://www.sastc.org.za/articles/xml-solv-prop.html
 
 
If you already understand XML then you are in a good position to start learning Docbook. If you do not understand XML the good news is that learning Docbook will help you learn XML. Below are two books that are a must read for anyone just starting with Docbook.
 
If you already understand XML then you are in a good position to start learning Docbook. If you do not understand XML the good news is that learning Docbook will help you learn XML. Below are two books that are a must read for anyone just starting with Docbook.
 
 
=== Further Reading ===
 
=== Further Reading ===
 
* Doc''''''Book - The Definitive Guide http://www.docbook.org/tdg/en/html/docbook.html
 
* Doc''''''Book - The Definitive Guide http://www.docbook.org/tdg/en/html/docbook.html
第39行: 第28行:
 
* Yelp - the Gnome help browser - uses DocBook/XML files directly. Templates may be found at http://developer.gnome.org/projects/gdp/templates.html
 
* Yelp - the Gnome help browser - uses DocBook/XML files directly. Templates may be found at http://developer.gnome.org/projects/gdp/templates.html
 
* Please read the DocBookReference if you want to know which tags to use where (and are too lazy or confused to look at the official reference).
 
* Please read the DocBookReference if you want to know which tags to use where (and are too lazy or confused to look at the official reference).
 
 
If you have installed the package 'docbook-defguide' you can access the guide either through your web browser as:  
 
If you have installed the package 'docbook-defguide' you can access the guide either through your web browser as:  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
http://localhost/doc/docbook-defguide/html/docbook.html (assuming that your Apache still has /doc aliased to /usr/share/doc) </nowiki></pre>
 
http://localhost/doc/docbook-defguide/html/docbook.html (assuming that your Apache still has /doc aliased to /usr/share/doc) </nowiki></pre>
 
 
You can also access it from the command line using::
 
You can also access it from the command line using::
 
<pre><nowiki>  
 
<pre><nowiki>  
 
lynx /usr/share/doc/docbook-defguide/html/docbook.html
 
lynx /usr/share/doc/docbook-defguide/html/docbook.html
 
</nowiki></pre>  
 
</nowiki></pre>  
 
 
Whilst reading these works it is useful to experiment. For this you will need an XML publishing tool-chain and an XML Editor. The Docbook Web site and Wiki will provide you with links to more information on the tool chain and editors you can use to author Docbook documents.
 
Whilst reading these works it is useful to experiment. For this you will need an XML publishing tool-chain and an XML Editor. The Docbook Web site and Wiki will provide you with links to more information on the tool chain and editors you can use to author Docbook documents.
 
 
For an explanation of the Ubuntu Documentation Projects usage of Docbook see the "[Ubuntu Docbook Interchange Protocol]."
 
For an explanation of the Ubuntu Documentation Projects usage of Docbook see the "[Ubuntu Docbook Interchange Protocol]."
 
 
=== Quick Tutorial ===
 
=== Quick Tutorial ===
 
 
==== What does DocBook look like? ====
 
==== What does DocBook look like? ====
 
DocBook defines a number of 'tags' just like HTML does. To set the authors name you would write something like...
 
DocBook defines a number of 'tags' just like HTML does. To set the authors name you would write something like...
 
 
<pre><nowiki>
 
<pre><nowiki>
 
<author>
 
<author>
第63行: 第45行:
 
</author>
 
</author>
 
</nowiki></pre>
 
</nowiki></pre>
 
 
As you can see this is very similar to HTML. Below is a working example of a complete XML document.
 
As you can see this is very similar to HTML. Below is a working example of a complete XML document.
 
 
The 'flavor' used to write these tags is XML. Therefore it is called
 
The 'flavor' used to write these tags is XML. Therefore it is called
 
DocBook/XML. (The other 'flavor' would be SGML which is not greatly different. XML
 
DocBook/XML. (The other 'flavor' would be SGML which is not greatly different. XML
第72行: 第52行:
 
converted to XML.) Even if you have not yet used XML you should not have
 
converted to XML.) Even if you have not yet used XML you should not have
 
much trouble.
 
much trouble.
 
 
==== Style sheets ====
 
==== Style sheets ====
 
To create the output document from your XML input you also need a
 
To create the output document from your XML input you also need a
第82行: 第61行:
 
the output file from it. We will use the free 'xsltproc' program
 
the output file from it. We will use the free 'xsltproc' program
 
for that purpose.
 
for that purpose.
 
 
There is a number of stylesheets available to convert your document into:
 
There is a number of stylesheets available to convert your document into:
 
 
- Postscript
 
- Postscript
 
- PDF
 
- PDF
第90行: 第67行:
 
- man
 
- man
 
- texinfo
 
- texinfo
 
 
Other converters exist to convert DocBook into formats like Yelp. Yelp is the the Gnome Help format.
 
Other converters exist to convert DocBook into formats like Yelp. Yelp is the the Gnome Help format.
 
 
==== Hello World ====
 
==== Hello World ====
 
First you need to install the following packages:
 
First you need to install the following packages:
第100行: 第75行:
 
- docbook-defguide (The Definitive Guide to DocBook - recommended)
 
- docbook-defguide (The Definitive Guide to DocBook - recommended)
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Enter these lines into a file and call it test.xml:
 
Enter these lines into a file and call it test.xml:
 
 
<pre><nowiki>  
 
<pre><nowiki>  
 
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://docbook.org/xml/4.2/docbookx.dtd">
 
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://docbook.org/xml/4.2/docbookx.dtd">
第116行: 第88行:
 
</sect1>
 
</sect1>
 
</article>
 
</article>
 
 
</nowiki></pre>  
 
</nowiki></pre>  
 
 
Please note that you should use UTF-8 as a character encoding.
 
Please note that you should use UTF-8 as a character encoding.
 
You may need to switch your terminal and your editor to UTF-8 mode too.
 
You may need to switch your terminal and your editor to UTF-8 mode too.
 
 
Run this command::
 
Run this command::
 
 
<pre><nowiki>  xsltproc -o test.html /usr/share/xml/docbook/stylesheet/nwalsh/xhtml/docbook.xsl test.xml
 
<pre><nowiki>  xsltproc -o test.html /usr/share/xml/docbook/stylesheet/nwalsh/xhtml/docbook.xsl test.xml
 
</nowiki></pre>
 
</nowiki></pre>
 
 
You should find a file 'test.html' in the current directory. View it with your
 
You should find a file 'test.html' in the current directory. View it with your
 
favorite web browser.
 
favorite web browser.
 
 
Now what did that line actually do?
 
Now what did that line actually do?
 
 
'xsltproc' is the converter program. '-o test.html' sets the output file.
 
'xsltproc' is the converter program. '-o test.html' sets the output file.
 
The next parameter '.../docbook.xsl' is the stylesheet you are using for
 
The next parameter '.../docbook.xsl' is the stylesheet you are using for
 
the conversion - this one converts XML to XHTML. And finally the 'test.xml'
 
the conversion - this one converts XML to XHTML. And finally the 'test.xml'
 
tells xsltproc where your input file is located.
 
tells xsltproc where your input file is located.
 
 
==== Customising style sheets ====
 
==== Customising style sheets ====
 
You will probably be disappointed with the look of the DocBook output.
 
You will probably be disappointed with the look of the DocBook output.
 
It is great to have it convert the document automatically but it probably
 
It is great to have it convert the document automatically but it probably
 
does not fit into your web design or 'corporate identity' at all. There is a remedy however.
 
does not fit into your web design or 'corporate identity' at all. There is a remedy however.
 
 
Style sheets usually provide a number of parameters that you can adjust.
 
Style sheets usually provide a number of parameters that you can adjust.
 
Usually you write your own stylesheet that imports the 'standard' style sheet. For example::
 
Usually you write your own stylesheet that imports the 'standard' style sheet. For example::
 
 
<pre><nowiki>  
 
<pre><nowiki>  
 
<?xml version='1.0'?>
 
<?xml version='1.0'?>
第156行: 第118行:
 
</xsl:stylesheet>
 
</xsl:stylesheet>
 
</nowiki></pre>  
 
</nowiki></pre>  
 
 
This stylesheet first imports the docbook.xsl mentioned earlier.
 
This stylesheet first imports the docbook.xsl mentioned earlier.
 
It also sets a few parameters:
 
It also sets a few parameters:
 
 
- Set the maximum depth of the TOC (table of contents) to '1'. So
 
- Set the maximum depth of the TOC (table of contents) to '1'. So
 
only the <sect1> sections will be included in the TOC.
 
only the <sect1> sections will be included in the TOC.
 
- The final XHTML document will use the 'ubuntu.css' style sheet (CSS).
 
- The final XHTML document will use the 'ubuntu.css' style sheet (CSS).
 
- Include a link to the main page on top of the page.
 
- Include a link to the main page on top of the page.
 
 
These settings only work with the XHTML style sheet. For other
 
These settings only work with the XHTML style sheet. For other
 
output format you need other settings. The settings above are documented
 
output format you need other settings. The settings above are documented
 
at /usr/share/doc/docbook-xsl/doc/html/index.html
 
at /usr/share/doc/docbook-xsl/doc/html/index.html
 
 
You will also want to use http://www.sagehill.net/docbookxsl/
 
You will also want to use http://www.sagehill.net/docbookxsl/
 
as a reference.
 
as a reference.
 
 
==== Makefile ====
 
==== Makefile ====
 
If you have multiple XML files or style sheets you may want to have all
 
If you have multiple XML files or style sheets you may want to have all
第178行: 第135行:
 
# Add your language file here:
 
# Add your language file here:
 
TARGETS = faq.html
 
TARGETS = faq.html
 
 
XSLTPROC = /usr/bin/xsltproc
 
XSLTPROC = /usr/bin/xsltproc
 
XSL = ubuntu.xsl
 
XSL = ubuntu.xsl
 
 
%.html: %.xml $(XSL)
 
%.html: %.xml $(XSL)
 
@$(XSLTPROC) -o $@ $(XSL) $<
 
@$(XSLTPROC) -o $@ $(XSL) $<
 
 
all: $(TARGETS)
 
all: $(TARGETS)
 
 
clean:
 
clean:
 
@rm -f *.html
 
@rm -f *.html
 
</nowiki></pre>
 
</nowiki></pre>
 
 
=== Editing Programs ===
 
=== Editing Programs ===
* Bluefish
+
# Bluefish
*** This editor has syntax highlighting and code snippets for DocBook and many other languages.
+
#* This editor has syntax highlighting and code snippets for DocBook and many other languages.
*** See http://bluefish.openoffice.nl/index.html
+
#** See http://bluefish.openoffice.nl/index.html
* conglomerate (WYSIWYG)
+
# conglomerate (WYSIWYG)
*** Somewhat beta. Doesn't hide the gory details. You still need to read the DocBook reference. Just makes it graphical.
+
#* Somewhat beta. Doesn't hide the gory details. You still need to read the DocBook reference. Just makes it graphical.
*** See http://www.conglomerate.org/
+
#** See http://www.conglomerate.org/
* VIM file type plugin "xmledit"
+
# VIM file type plugin "xmledit"
*** Good for vim-lovers. See http://www.vim.org/scripts/script.php?script_id=301
+
#* Good for vim-lovers. See http://www.vim.org/scripts/script.php?script_id=301
*** A recent update based on the above script. http://www.vim.org/scripts/script.php?script_id=1397
+
#** A recent update based on the above script. http://www.vim.org/scripts/script.php?script_id=1397
* EMACS XML support
+
# EMACS XML support
*** Some say DocBook is easy to write only under psgml.  Some use Emacs only for psgml-mode.
+
#* Some say DocBook is easy to write only under psgml.  Some use Emacs only for psgml-mode.
*** [http://www.thaiopensource.com/nxml-mode/ nxml-mode] however is far superior to psgml-mode. It does real-time syntax and error highlighting.
+
#** [http://www.thaiopensource.com/nxml-mode/ nxml-mode] however is far superior to psgml-mode. It does real-time syntax and error highlighting.
* See also DocBookEditors.
+
# See also DocBookEditors.
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 16:48的版本


Purpose

The purpose of this page is to give an overview of the DocBook format. It offers an explanation of the advantages of this format, links further reading on this subject and contains a short tutorial.

What is DocBook?

DocBook is an XML based standard, which is used in many of todays documentation tasks. Practically speaking, when you want to create a DocBook document source, you write XML files which describe the documents layout, paragraph division and other attributes. XML file structure may look familiar to you if you have seen HTML code before. XML tends to be an improvment over the older HTML specification and can be used to produce complete web pages and other markup documents.

What are the Advantages of Docbook?

Docbook is an OASIS standard and the format in which most open source projects store their documentation. Docbook is developed as an open source application. The project is hosted at Source'Forge and is made available under the GPL. Docbook is available as a Document Type Definition (DTD) and XML Schema (XSD). The project has a large developer and support community spanning both open source and commercial groups. The most important reasons why the project uses Docbook include:

  1. Docbook is a standard
  2. Docbook is open source
  3. Docbook is used by most major projects
  4. Docbook has a large developer and support community

Docbook is also an XML application and XML technologies solve a number of publishing problems for documentation teams, including:

  • Single-sourcing
  • Collaborative authoring
  • Cross-platform editing
  • Multi-channel publishing
  • Improving information quality and consistency
  • Enhancing functionality of electronic output
  • Negating vendor lock-in

More information on these points can be found at http://www.sastc.org.za/articles/xml-solv-prop.html If you already understand XML then you are in a good position to start learning Docbook. If you do not understand XML the good news is that learning Docbook will help you learn XML. Below are two books that are a must read for anyone just starting with Docbook.

Further Reading

If you have installed the package 'docbook-defguide' you can access the guide either through your web browser as:

 
http://localhost/doc/docbook-defguide/html/docbook.html (assuming that your Apache still has /doc aliased to /usr/share/doc) 

You can also access it from the command line using::

 
lynx /usr/share/doc/docbook-defguide/html/docbook.html

Whilst reading these works it is useful to experiment. For this you will need an XML publishing tool-chain and an XML Editor. The Docbook Web site and Wiki will provide you with links to more information on the tool chain and editors you can use to author Docbook documents. For an explanation of the Ubuntu Documentation Projects usage of Docbook see the "[Ubuntu Docbook Interchange Protocol]."

Quick Tutorial

What does DocBook look like?

DocBook defines a number of 'tags' just like HTML does. To set the authors name you would write something like...

<author>
Christoph Haas
</author>

As you can see this is very similar to HTML. Below is a working example of a complete XML document. The 'flavor' used to write these tags is XML. Therefore it is called DocBook/XML. (The other 'flavor' would be SGML which is not greatly different. XML is stricter than SGML. HTML is a kind of SGML language. Most people believe that SGML is deprecated. Thus documentation in Debian is currently converted to XML.) Even if you have not yet used XML you should not have much trouble.

Style sheets

To create the output document from your XML input you also need a style sheet. Stylesheets are called 'XSL Transformations' (XSLT) and are written in a language called 'Extensible Stylesheet Language' (XSL). Basically XSLT describes how to convert one document into another. Usually you will not need to know how style sheets look. You also need a 'processor' that takes the XML and the XSLT and creates the output file from it. We will use the free 'xsltproc' program for that purpose. There is a number of stylesheets available to convert your document into: - Postscript - PDF - XHTML - man - texinfo Other converters exist to convert DocBook into formats like Yelp. Yelp is the the Gnome Help format.

Hello World

First you need to install the following packages:

- xsltproc (the XSL Transformations Processor)
- docbook-xsl (stylesheets for HTML, XHTML, HTML Help and others)
- docbook-defguide (The Definitive Guide to DocBook - recommended)

Enter these lines into a file and call it test.xml:

 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://docbook.org/xml/4.2/docbookx.dtd">
<article>
<title>My first Docbook document</title>
<sect1>
<title>The greeting</title>
<para>
Hello world
</para>
</sect1>
</article>

Please note that you should use UTF-8 as a character encoding. You may need to switch your terminal and your editor to UTF-8 mode too. Run this command::

  xsltproc -o test.html /usr/share/xml/docbook/stylesheet/nwalsh/xhtml/docbook.xsl test.xml

You should find a file 'test.html' in the current directory. View it with your favorite web browser. Now what did that line actually do? 'xsltproc' is the converter program. '-o test.html' sets the output file. The next parameter '.../docbook.xsl' is the stylesheet you are using for the conversion - this one converts XML to XHTML. And finally the 'test.xml' tells xsltproc where your input file is located.

Customising style sheets

You will probably be disappointed with the look of the DocBook output. It is great to have it convert the document automatically but it probably does not fit into your web design or 'corporate identity' at all. There is a remedy however. Style sheets usually provide a number of parameters that you can adjust. Usually you write your own stylesheet that imports the 'standard' style sheet. For example::

 
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="/usr/share/xml/docbook/stylesheet/nwalsh/xhtml/docbook.xsl"/>
<xsl:param name="toc.max.depth">1</xsl:param>
<xsl:param name="html.stylesheet" select="'/ubuntu.css'"/>
<xsl:template name="user.header.content">
<a href="/">Back to main page</a>
</xsl:template>
</xsl:stylesheet>

This stylesheet first imports the docbook.xsl mentioned earlier. It also sets a few parameters: - Set the maximum depth of the TOC (table of contents) to '1'. So only the <sect1> sections will be included in the TOC. - The final XHTML document will use the 'ubuntu.css' style sheet (CSS). - Include a link to the main page on top of the page. These settings only work with the XHTML style sheet. For other output format you need other settings. The settings above are documented at /usr/share/doc/docbook-xsl/doc/html/index.html You will also want to use http://www.sagehill.net/docbookxsl/ as a reference.

Makefile

If you have multiple XML files or style sheets you may want to have all the processing done in a Makefile. For example::

 
# Add your language file here:
TARGETS = faq.html
XSLTPROC = /usr/bin/xsltproc
XSL = ubuntu.xsl
%.html: %.xml $(XSL)
@$(XSLTPROC) -o $@ $(XSL) $<
all: $(TARGETS)
clean:
@rm -f *.html

Editing Programs

  1. Bluefish
  2. conglomerate (WYSIWYG)
    • Somewhat beta. Doesn't hide the gory details. You still need to read the DocBook reference. Just makes it graphical.
  3. VIM file type plugin "xmledit"
  4. EMACS XML support
    • Some say DocBook is easy to write only under psgml. Some use Emacs only for psgml-mode.
      • nxml-mode however is far superior to psgml-mode. It does real-time syntax and error highlighting.
  5. See also DocBookEditors.