From: Bob Stayton Date: Mon, 16 Apr 2012 02:35:47 +0000 (+0000) Subject: Check in initial versions of assembly stylesheet. X-Git-Tag: release/1.79.1~6^2~491 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b336b0991c34f754dcb08c68c251980ef96f55d6;p=docbook-dsssl Check in initial versions of assembly stylesheet. --- diff --git a/xsl/assembly/README b/xsl/assembly/README new file mode 100644 index 000000000..765f6a26b --- /dev/null +++ b/xsl/assembly/README @@ -0,0 +1,194 @@ +DocBook Assembly Stylesheets +============================== +bobs@sagehill.net + +This directory provides XSL stylesheets for working with +DocBook assemblies. It is intended to enable working with + and elements, as defined in DocBook 5.1 +and later. + +This kit currently supports most features of an assembly. +See the "Unsupported Features" section below for details +of what is not currently supported. These more advanced +features will be supported as it is further developed. + + +Content of this directory: +-------------------------- +topic-maker-chunk.xsl - stylesheet to modularize an existing document. +topic-maker.xsl - imported by topic-maker-chunk.xsl. +assemble.xsl - stylesheet to process an into a document. + + +The toolkit consists of an assemble.xsl XSL stylesheet +to process a DocBook element to convert it +to an assembled DocBook document ready to be formatted. +This stylesheet will enable users to structure a book from +modular files. + +To make it easy to initially create a modular book, this +kit also includes a topic-maker-chunk.xsl XSL stylesheet +to break apart an existing DocBook 5 book into modular +files, and also create the associated document. +Then you can run the assemble.xsl stylesheet to put it +back together as a single DocBook document. + + +To create an assembly and topic files from a book or article document +======================================================================= + +If you have an existing DocBook book or article document, +you can convert it to an assembly and a collection of +modular topic files. + +For example, to disassemble a book document named book.xml: + +xsltproc --xinclude \ + --stringparam assembly.filename myassembly.xml \ + --stringparam base.dir topics/ \ + topic-maker-chunk.xsl \ + mybook.xml + +This command will result in a master assembly file named +'myassembly.xml' with a root element of , containing +a single element. It will also break up the +content of the book into modular chunks that are output +to the 'topics/' subdirectory as specified in the 'base.dir' +parameter. + +Options +---------- +The name of the assembly file is set by the stylesheet param +named 'assembly.filename', which should include the filename suffix. + +Modular files are output to the directory location specified +by the 'base.dir' parameter. If you want them in the current +directory, then don't set that param. + +By default the assembly element is output to the current +directory, *not* into base.dir with the modular files. +The element in the assembly has its xml:base +attribute set to the value of 'base.dir', so that it is +added to the paths to the modular files when processed. +If you set the stylesheet param 'manifest.in.base.dir' +to 1, then the assembly file is created in the base.dir +directory and the xml:base attribute is omitted (since +they are together in the same directory). + +If you want the assembly file in 'base.dir' instead of +the current directory, then set the stylesheet param +'manifest.in.base.dir' to 1. + +The stylesheet chunks a document into modules at the +same boundaries as the chunking XHTML stylesheet, because +it reuses many of the chunking stylesheet templates. +You can alter the chunking behavior with the same options +as for XHTML chunking. + +For example, the stylesheet will chunk sections into topics +down to section level 3 by default. To change that level, +change the stylesheet param 'chunk.section.depth' to +another value. + +Finer control of chunking can be achieved by using +the processing instruction in +the source file. + +Many modular elements retain their original element name, +such as glossary, bibliography, index, and such. By default, the +stylesheet converts chapter, article, preface and section elements +into modules. To change that list of +converted element names, alter the stylesheet param named +'topic.elements'. If that param is empty, then no elements +will be converted to , so they will all retain their +original element names. + +Modular filenames use the same naming scheme as the chunking +XHTML stylesheet, and supports the same file naming options such as +the param 'use.id.as.filename', which is set to 1 by default. +Note that the stylesheet param 'html.ext' is set to '.xml' +because it is producing modular XML files, not HTML files. + +Root element conversion +------------------------ +By default, the root element of the original document is +also converted to a module, and gets a resourceref +attribute to reference it. If you set the stylesheet +param 'root.as.resourceref' to zero, then the root element +is handled differently, as described as follows. + +If the structure element does not have a resourcref +attribute, the root element is constructed rather +than copied from a resource. The structure element must +have a renderas attribute (or its child output element must +have such) to select the output root element name. + +Any content between the root element start tag and the +first module is put into a resource with the original +root element. To pull this content in, the first +module in the structure points to this resource but +uses a contentonly="yes" attribute. The effect of +that attribute is to pull in all content *except* +the root element of that resource. + +In general, if you have content that does not logically +have its own container element, you can put the content +into a suitable container element and then deselect the +container element upon assembly with the contentonly="yes" +attribute. That attribute can also be used to avoid +pulling in a resource's xml:id when you want to change it. + + +To process an into an assembled DocBook document +============================================================== + +To convert an and its associated modular +files into a single DocBook document, process +your assembly document with the assemble.xsl stylesheet. +You should then be able to process the resulting +document with a DocBook XSL formatting stylesheet. + + + + +Useful params in assemble.xsl +----------------------------- +The $root.default.renderas param sets the name of the +root element of the assembled document, if it is not +otherwise specified with @renderas. Its default value +is 'book'. + +The $topic.default.renderas param sets the name of the +output element for any topic element included in the +assembly, if it is not otherwise specified with +@renderas. It's default value is 'section'. + +The $structure.id param lets you specify at runtime +the id value of the structure you want to reassemble. +This is only necessary if you have more than one +structure element in your assembly. + +The $output.type param also lets you specify at runtime +which structure element to process. In this case, +the value should match on an @type attribute on +the structure element. + +The $output.format param lets you specify at runtime +which of several possible output formats are being generated. +The param value is compared to the @format +attribute on elements to select specific properties +for a module. + + + +Unsupported Features +----------------------- + +The transforms and transform elements are currently ignored +by the assembly stylesheet. + +The relationships and relationship elements are currently +ignored by the assembly stylesheet. + +The filterin and filterout elements are not currently +supported. diff --git a/xsl/assembly/assemble.xsl b/xsl/assembly/assemble.xsl new file mode 100644 index 000000000..9cebcdf93 --- /dev/null +++ b/xsl/assembly/assemble.xsl @@ -0,0 +1,656 @@ + + + + + + + + + + + +5.0 +book +section + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: structure.id param set to ' + + ' but no element with that xml:id exists in assembly. + + + + + ERROR: structure.id param set to ' + + ' but no structure with that xml:id exists in assembly. + + + + + + + + + + ERROR: output.type param set to ' + + but no structure element has that type attribute. Exiting. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + renderas + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: cannot determine output element name for + module with no @resourceref and no @renderas. Exiting. + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: cannot determine output element name for + @resourceref=" + + ". Exiting. + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: cannot determine output element name for + structure with no @renderas and no $root.default.renderas. + Exiting. + + + + + + + + + + + + + + + + ERROR: no xml:id matches @resourceref = ' + + '. + + + + + ERROR: xml:id matching @resourceref = ' + + is not a resource element'. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: @fileref = ' + + ' has no content or is unresolved. + + + + + + + + + + + + omittitles + + + + + + contentonly + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: no xml:id matches @resourceref = ' + + '. + + + + + ERROR: xml:id matching @resourceref = ' + + is not a resource element'. + + + + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: merge element with resourceref ' + + ' must point to something with an info element.' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + WARNING: the <relationships> element is not currently + supported by this stylesheet. + + + + + + WARNING: the <transforms> element is not currently + supported by this stylesheet. + + + + + + WARNING: the <filterin> element is not currently + supported by this stylesheet. + + + + + + WARNING: the <filterin> element is not currently + supported by this stylesheet. + + + + diff --git a/xsl/assembly/topic-maker-chunk.xsl b/xsl/assembly/topic-maker-chunk.xsl new file mode 100644 index 000000000..ccb07ea6e --- /dev/null +++ b/xsl/assembly/topic-maker-chunk.xsl @@ -0,0 +1,222 @@ + + + + + + + + + + +-info + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + yes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xsl/assembly/topic-maker.xsl b/xsl/assembly/topic-maker.xsl new file mode 100644 index 000000000..5e6450227 --- /dev/null +++ b/xsl/assembly/topic-maker.xsl @@ -0,0 +1,79 @@ + + + + + + + + + + +myassembly.xml + + + +.xml +topics/ + + +xhtml + + + + + + + + + + + +http://docbook.org/ns/docbook + + +preface chapter article section + + + + + + + + + + + + + + + + + + + + + + + + + + + + topic + + + + + + + + +