]> granicus.if.org Git - docbook-dsssl/commitdiff
Check in initial versions of assembly stylesheet.
authorBob Stayton <bobs@sagehill.net>
Mon, 16 Apr 2012 02:35:47 +0000 (02:35 +0000)
committerBob Stayton <bobs@sagehill.net>
Mon, 16 Apr 2012 02:35:47 +0000 (02:35 +0000)
xsl/assembly/README [new file with mode: 0644]
xsl/assembly/assemble.xsl [new file with mode: 0644]
xsl/assembly/topic-maker-chunk.xsl [new file with mode: 0644]
xsl/assembly/topic-maker.xsl [new file with mode: 0644]

diff --git a/xsl/assembly/README b/xsl/assembly/README
new file mode 100644 (file)
index 0000000..765f6a2
--- /dev/null
@@ -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
+<topic> and <assembly> 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 <assembly> into a document.
+
+
+The toolkit consists of an assemble.xsl XSL stylesheet
+to process a DocBook <assembly> 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 <assembly> 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 <assembly>, containing
+a single <structure> 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 <resources> 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 <?dbhtml stop-chunking?> 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 <topic> 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 <topic>, 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 <structure> 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 <assembly> into an assembled DocBook document
+==============================================================
+
+To convert an <assembly> 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 <output> 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 (file)
index 0000000..9cebcdf
--- /dev/null
@@ -0,0 +1,656 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet 
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+  xmlns:exsl="http://exslt.org/common"
+  xmlns:d="http://docbook.org/ns/docbook"
+  xmlns:xlink="http://www.w3.org/1999/xlink"
+  xmlns="http://docbook.org/ns/docbook"
+  exclude-result-prefixes="exsl d xlink"
+  version="1.0">
+
+<!-- $Id: assemble.xsl,v 1.10 2012-04-10 07:56:58 bobs Exp $ -->
+
+<xsl:preserve-space elements="*"/>
+<xsl:strip-space elements="d:assembly d:structure d:module d:resources d:resource"/>
+
+<xsl:key name="id" match="*" use="@id|@xml:id"/>
+
+
+<xsl:param name="docbook.version">5.0</xsl:param>
+<xsl:param name="root.default.renderas">book</xsl:param>
+<xsl:param name="topic.default.renderas">section</xsl:param>
+
+<xsl:param name="output.type" select="''"/>
+<xsl:param name="output.format" select="''"/>
+<!-- May be used to select one structure among several to  process -->
+<xsl:param name="structure.id" select="''"/>
+
+
+<!-- default mode is to copy all content nodes -->
+<xsl:template match="node()|@*" priority="-5" mode="copycontent">
+  <xsl:param name="omittitles"/>
+    <xsl:copy>
+      <xsl:apply-templates select="@*" mode="copycontent"/>
+      <xsl:apply-templates mode="copycontent">
+        <xsl:with-param name="omittitles" select="$omittitles"/>
+      </xsl:apply-templates>
+   </xsl:copy>
+</xsl:template>
+
+<xsl:template match="processing-instruction('oxygen')"/>
+
+<!-- skip assembly info elements -->
+<xsl:template match="d:info"/>
+
+<!-- including for structure info element -->
+<xsl:template match="d:structure/d:info"/>
+
+<!-- handle omittitles, but only top level title of resource -->
+<xsl:template match="/*/d:title 
+                   | /*/d:info/d:title 
+                   | /*/d:subtitle  
+                   | /*/d:info/d:subtitle
+                   | /*/d:titleabbrev  
+                   | /*/d:info/d:titleabbrev"
+              mode="copycontent">
+  <xsl:param name="omittitles"/>
+
+  <xsl:choose>
+    <xsl:when test="$omittitles = 'yes' or $omittitles = 'true' or $omittitles = '1'">
+      <!-- omit it -->
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:copy>
+        <xsl:apply-templates select="@*" mode="copycontent"/>
+        <xsl:apply-templates mode="copycontent"/>
+      </xsl:copy>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- handled in a mode -->
+<xsl:template match="d:resources"/>
+<xsl:template match="d:output|d:filterin|d:filterout|d:merge|d:revhistory"/>
+<xsl:template match="d:output|d:filterin|d:filterout|d:merge|d:revhistory"
+              mode="copycontent"/>
+
+<xsl:template match="d:assembly">
+  <xsl:choose>
+    <xsl:when test="$structure.id != ''">
+      <xsl:variable name="id.structure" select="key('id', $structure.id)"/>
+      <xsl:choose>
+        <xsl:when test="count($id.structure) = 0">
+          <xsl:message terminate="yes">
+            <xsl:text>ERROR: structure.id param set to '</xsl:text>
+            <xsl:value-of select="$structure.id"/>
+            <xsl:text>' but no element with that xml:id exists in assembly.</xsl:text>
+          </xsl:message>
+        </xsl:when>
+        <xsl:when test="local-name($id.structure) != 'structure'">
+          <xsl:message terminate="yes">
+            <xsl:text>ERROR: structure.id param set to '</xsl:text>
+            <xsl:value-of select="$structure.id"/>
+            <xsl:text>' but no structure with that xml:id exists in assembly.</xsl:text>
+          </xsl:message>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:apply-templates select="key('id', $structure.id)"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:when>
+    <xsl:when test="$output.type != '' and not(d:structure[@type = $output.type])">
+      <xsl:message terminate="yes">
+        <xsl:text>ERROR: output.type param set to '</xsl:text>
+        <xsl:value-of select="$output.type"/>
+        <xsl:text> but no structure element has that type attribute. Exiting.</xsl:text>
+      </xsl:message>
+    </xsl:when>
+    <xsl:when test="$output.type != '' and d:structure[@type = $output.type]">
+      <xsl:apply-templates select="d:structure[@type = $output.type][1]"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <!-- otherwise process the first structure -->
+      <xsl:apply-templates select="d:structure[1]"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="d:structure[not(@resourceref)]">
+
+  <xsl:variable name="output.root.element">
+    <xsl:apply-templates select="." mode="compute.element.name"/>
+  </xsl:variable>
+
+  <xsl:element name="{$output.root.element}" namespace="http://docbook.org/ns/docbook">
+    <xsl:attribute name="version">
+      <xsl:value-of select="$docbook.version"/>
+    </xsl:attribute>
+    <xsl:copy-of select="@xml:id"/>
+
+    <xsl:apply-templates> 
+      <xsl:with-param name="parent" select="$output.root.element"/>
+    </xsl:apply-templates>
+
+  </xsl:element>
+</xsl:template>
+
+<xsl:template match="d:glossary|d:bibliography|d:index|d:toc">
+   <xsl:param name="parent" select="''"/>
+  <xsl:apply-templates select="." mode="copycontent"/>
+</xsl:template>
+
+<xsl:template match="d:title|d:titleabbrev|d:subtitle">
+   <xsl:param name="parent" select="''"/>
+  <xsl:apply-templates select="." mode="copycontent"/>
+</xsl:template>
+
+<!-- module without a resourceref creates an element -->
+<xsl:template match="d:module[not(@resourceref)]">
+  <xsl:param name="parent" select="''"/>
+  
+  <xsl:variable name="module" select="."/>
+
+  <xsl:variable name="element.name">
+    <xsl:apply-templates select="." mode="compute.element.name"/>
+  </xsl:variable>
+
+  <xsl:element name="{$element.name}" namespace="http://docbook.org/ns/docbook">
+    <xsl:choose>
+      <!-- Use the module's xml:id if it has one -->
+      <xsl:when test="@xml:id">
+        <xsl:attribute name="xml:id">
+          <xsl:value-of select="@xml:id"/>
+        </xsl:attribute>
+      </xsl:when>
+    </xsl:choose>
+
+    <xsl:call-template name="merge.info">
+      <xsl:with-param name="merge.element" select="$module/d:merge"/>
+    </xsl:call-template>
+      
+    <xsl:apply-templates>
+      <xsl:with-param name="parent" select="$element.name"/>
+    </xsl:apply-templates>
+
+  </xsl:element>
+</xsl:template>
+
+<xsl:template name="compute.renderas">
+  <xsl:variable name="output.value">
+    <xsl:call-template name="compute.output.value">
+      <xsl:with-param name="property">renderas</xsl:with-param>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <xsl:value-of select="$output.value"/>
+
+</xsl:template>
+
+<!-- This utility template is passed a value for output format
+     and the name of a property and computes the value
+     of the property from output children of context element -->
+<xsl:template name="compute.output.value">
+  <xsl:param name="property" select="''"/>
+  
+  <xsl:variable name="default.format"
+                select="ancestor::d:structure/@defaultformat"/>
+
+  <xsl:variable name="property.value">
+    <xsl:choose>
+      <!-- if a child output element has a format that matches the param value 
+           and it has that property -->
+      <!-- The format attribute can be multivalued -->
+      <xsl:when test="$output.format != '' and 
+                      d:output[contains(concat(' ', normalize-space(@format), ' '),  
+                                 $output.format)]
+                        [@*[local-name() = $property]]">
+        <xsl:value-of 
+           select="d:output[contains(concat(' ', normalize-space(@format), ' '), 
+                              $output.format)]
+                           [@*[local-name() = $property]][1]
+                           /@*[local-name() = $property]"/>
+      </xsl:when>
+      <!-- try with the structure's @defaultformat -->
+      <xsl:when test="$default.format != '' and 
+                      d:output[contains(concat(' ', normalize-space(@format), ' '),  
+                                 $default.format)]
+                        [@*[local-name() = $property]]">
+        <xsl:value-of 
+           select="d:output[contains(concat(' ', normalize-space(@format), ' '), 
+                              $default.format)]
+                           [@*[local-name() = $property]][1]
+                           /@*[local-name() = $property]"/>
+      </xsl:when>
+      <!-- try the first output with the property-->
+      <xsl:when test="d:output[@*[local-name() = $property]]">
+        <xsl:value-of 
+           select="d:output[@*[local-name() = $property]][1]
+                           /@*[local-name() = $property]"/>
+      </xsl:when>
+      <!-- and try the module element itself -->
+      <xsl:when test="@*[local-name() = $property]">
+        <xsl:value-of 
+           select="@*[local-name() = $property]"/>
+      </xsl:when>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:value-of select="$property.value"/>
+</xsl:template>
+
+<xsl:template match="d:module[not(@resourceref)]" mode="compute.element.name">
+
+  <xsl:variable name="renderas">
+    <xsl:call-template name="compute.renderas"/>
+  </xsl:variable>
+
+  <xsl:choose>
+    <xsl:when test="string-length($renderas) != 0">
+      <xsl:value-of select="$renderas"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:message terminate="yes">
+        <xsl:text>ERROR: cannot determine output element name for </xsl:text>
+        <xsl:text>module with no @resourceref and no @renderas. Exiting.</xsl:text>
+      </xsl:message>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="d:module[@resourceref]" mode="compute.element.name">
+  <xsl:param name="ref.name" select="''"/>
+
+  <xsl:variable name="renderas">
+    <xsl:call-template name="compute.renderas"/>
+  </xsl:variable>
+
+  <xsl:choose>
+    <xsl:when test="string-length($renderas) != 0">
+      <xsl:value-of select="$renderas"/>
+    </xsl:when>
+    <xsl:when test="$ref.name = 'topic' and 
+                    string-length($topic.default.renderas) != 0"> 
+      <xsl:value-of select="$topic.default.renderas"/>
+    </xsl:when>
+    <xsl:when test="string-length($ref.name) != 0">
+      <xsl:value-of select="$ref.name"/> 
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:message terminate="yes">
+        <xsl:text>ERROR: cannot determine output element name for </xsl:text>
+        <xsl:text>@resourceref="</xsl:text>
+        <xsl:value-of select="@resourceref"/>
+        <xsl:text>". Exiting.</xsl:text>
+      </xsl:message>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="d:structure" mode="compute.element.name">
+  <xsl:param name="ref.name" select="''"/>
+
+  <xsl:variable name="renderas">
+    <xsl:call-template name="compute.renderas"/>
+  </xsl:variable>
+
+  <xsl:choose>
+    <xsl:when test="string-length($renderas) != 0">
+      <xsl:value-of select="$renderas"/>
+    </xsl:when>
+    <xsl:when test="string-length($ref.name) != 0">
+      <xsl:value-of select="$ref.name"/> 
+    </xsl:when>
+    <xsl:when test="string-length($root.default.renderas) != 0">
+      <xsl:value-of select="$root.default.renderas"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:message terminate="yes">
+        <xsl:text>ERROR: cannot determine output element name for </xsl:text>
+        <xsl:text>structure with no @renderas and no $root.default.renderas. </xsl:text>
+        <xsl:text>Exiting.</xsl:text>
+      </xsl:message>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="d:module[@resourceref] | d:structure[@resourceref]">
+  <xsl:param name="parent" select="''"/>
+
+  <xsl:variable name="module" select="."/>
+  <xsl:variable name="resourceref" select="@resourceref"/>
+  <xsl:variable name="resource" select="key('id', $resourceref)"/>
+
+  <xsl:choose>
+    <xsl:when test="not($resource)">
+      <xsl:message terminate="yes">
+        <xsl:text>ERROR: no xml:id matches @resourceref = '</xsl:text>
+        <xsl:value-of select="$resourceref"/>
+        <xsl:text>'.</xsl:text>
+      </xsl:message>
+    </xsl:when>
+    <xsl:when test="not($resource/self::d:resource)">
+      <xsl:message terminate="yes">
+        <xsl:text>ERROR: xml:id matching @resourceref = '</xsl:text>
+        <xsl:value-of select="$resourceref"/>
+        <xsl:text> is not a resource element'.</xsl:text>
+      </xsl:message>
+    </xsl:when>
+  </xsl:choose>
+
+  <xsl:variable name="fileref.att" select="$resource/@fileref"/>
+  <xsl:variable name="fileref">
+    <xsl:choose>
+      <xsl:when test="$resource/ancestor::d:resources/@xml:base">
+        <xsl:value-of 
+            select="concat($resource/ancestor::d:resources[@xml:base][1]/@xml:base,
+                                 '/', $fileref.att)"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$fileref.att"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:choose>
+    <xsl:when test="string-length($fileref) = 0">
+      <!-- A resource without @fileref gets its content copied -->
+      <xsl:apply-templates select="$resource/node()" mode="copycontent"/>
+    </xsl:when>
+    <xsl:otherwise>
+
+      <xsl:variable name="ref.content" select="document($fileref,/)"/>
+    
+      <xsl:variable name="ref.root" select="$ref.content/*[1]"/>
+
+      <xsl:if test="count($ref.root) = 0">
+        <xsl:message terminate="yes">
+          <xsl:text>ERROR: @fileref = '</xsl:text>
+          <xsl:value-of select="$fileref"/>
+          <xsl:text>' has no content or is unresolved.</xsl:text>
+        </xsl:message>
+      </xsl:if>
+    
+      <xsl:variable name="element.name">
+        <xsl:apply-templates select="." mode="compute.element.name">
+          <xsl:with-param name="ref.name" select="local-name($ref.content/*[1])"/>
+        </xsl:apply-templates>
+      </xsl:variable>
+
+      <xsl:variable name="omittitles.property">
+        <xsl:call-template name="compute.output.value">
+          <xsl:with-param name="property">omittitles</xsl:with-param>
+        </xsl:call-template>
+      </xsl:variable>
+    
+      <xsl:variable name="contentonly.property">
+        <xsl:call-template name="compute.output.value">
+          <xsl:with-param name="property">contentonly</xsl:with-param>
+        </xsl:call-template>
+      </xsl:variable>
+    
+      <xsl:choose>
+        <xsl:when test="$contentonly.property = 'true' or 
+                        $contentonly.property = 'yes' or
+                        $contentonly.property = '1'">
+          <xsl:apply-templates select="$ref.content/*[1]/node()" mode="copycontent">
+            <xsl:with-param name="omittitles" select="$omittitles.property"/>
+          </xsl:apply-templates>
+        </xsl:when>
+        <!-- use xsl:copy if using the ref element to get its namespaces -->
+        <xsl:when test="$element.name = local-name($ref.root)">
+          <!-- must use for-each to set context node for xsl:copy -->
+          <xsl:for-each select="$ref.root">
+            <xsl:copy>
+              <xsl:copy-of select="@*[not(name = 'xml:id')]"/>
+              <xsl:choose>
+                <!-- Use the module's xml:id if it has one -->
+                <xsl:when test="$module/@xml:id">
+                  <xsl:attribute name="xml:id">
+                    <xsl:value-of select="$module/@xml:id"/>
+                  </xsl:attribute>
+                </xsl:when>
+                <!-- otherwise use the resource's id -->
+                <xsl:otherwise>
+                  <xsl:copy-of select="@xml:id"/>
+                </xsl:otherwise>
+              </xsl:choose>
+          
+              <xsl:call-template name="merge.info">
+                <xsl:with-param name="merge.element" select="$module/d:merge"/>
+                <xsl:with-param name="ref.content" select="$ref.content"/>
+                <xsl:with-param name="omittitles" select="$omittitles.property"/>
+              </xsl:call-template>
+      
+              <!-- copy through all but titles, which moved to info -->
+              <xsl:apply-templates select="node()
+                       [not(local-name() = 'title') and
+                        not(local-name() = 'subtitle') and
+                        not(local-name() = 'info') and
+                        not(local-name() = 'titleabbrev')]" mode="copycontent"/>
+          
+              <xsl:apply-templates select="$module/node()"> 
+                <xsl:with-param name="parent" select="$element.name"/>
+              </xsl:apply-templates>
+            </xsl:copy>
+          </xsl:for-each>
+        </xsl:when>
+        <xsl:otherwise>
+          <!-- create the element instead of copying it -->
+          <xsl:element name="{$element.name}" namespace="http://docbook.org/ns/docbook">
+            <xsl:copy-of select="$ref.content/*[1]/@*[not(name = 'xml:id')]"/>
+            <xsl:choose>
+              <!-- Use the module's xml:id if it has one -->
+              <xsl:when test="@xml:id">
+                <xsl:attribute name="xml:id">
+                  <xsl:value-of select="@xml:id"/>
+                </xsl:attribute>
+              </xsl:when>
+              <!-- otherwise use the resource's id -->
+              <xsl:when test="$ref.content/*[1]/@xml:id">
+                <xsl:attribute name="xml:id">
+                  <xsl:value-of select="$ref.content/*[1]/@xml:id"/>
+                </xsl:attribute>
+              </xsl:when>
+            </xsl:choose>
+        
+            <xsl:call-template name="merge.info">
+              <xsl:with-param name="merge.element" select="d:merge"/>
+              <xsl:with-param name="ref.content" select="$ref.content"/>
+              <xsl:with-param name="omittitles" select="$omittitles.property"/>
+            </xsl:call-template>
+    
+            <!-- copy through all but titles, which moved to info -->
+            <xsl:apply-templates select="$ref.content/*[1]/node()
+                     [not(local-name() = 'title') and
+                      not(local-name() = 'subtitle') and
+                      not(local-name() = 'info') and
+                      not(local-name() = 'titleabbrev')]" mode="copycontent"/>
+        
+            <xsl:apply-templates> 
+              <xsl:with-param name="parent" select="$element.name"/>
+            </xsl:apply-templates>
+          </xsl:element>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="merge.info">
+  <xsl:param name="merge.element" select="NOTANODE"/>
+  <xsl:param name="ref.content" select="NOTANODE"/>
+  <xsl:param name="omittitles"/> 
+
+  <!-- a merge element may use resourceref as well as literal content -->
+  <!-- any literal content overrides the merge resourceref content -->
+  <xsl:variable name="merge.ref.content">
+    <xsl:if test="$merge.element/@resourceref">
+      <xsl:variable name="resourceref" select="$merge.element/@resourceref"/>
+      <xsl:variable name="resource" select="key('id', $resourceref)"/>
+
+      <xsl:choose>
+        <xsl:when test="not($resource)">
+          <xsl:message terminate="yes">
+            <xsl:text>ERROR: no xml:id matches @resourceref = '</xsl:text>
+            <xsl:value-of select="$resourceref"/>
+            <xsl:text>'.</xsl:text>
+          </xsl:message>
+        </xsl:when>
+        <xsl:when test="not($resource/self::d:resource)">
+          <xsl:message terminate="yes">
+            <xsl:text>ERROR: xml:id matching @resourceref = '</xsl:text>
+            <xsl:value-of select="$resourceref"/>
+            <xsl:text> is not a resource element'.</xsl:text>
+          </xsl:message>
+        </xsl:when>
+      </xsl:choose>
+
+      <xsl:variable name="fileref.att" select="$resource/@fileref"/>
+
+      <xsl:variable name="fileref">
+        <xsl:choose>
+          <xsl:when test="$resource/ancestor::d:resources/@xml:base">
+            <xsl:value-of 
+                select="concat($resource/ancestor::d:resources[@xml:base][1]/@xml:base,
+                               '/', $fileref.att)"/>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$fileref.att"/>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+
+      <xsl:if test="string-length($fileref) != 0">
+        <xsl:copy-of select="document($fileref,/)"/>
+      </xsl:if>
+    </xsl:if>
+  </xsl:variable>
+
+  <xsl:variable name="merge.ref.info" 
+                select="exsl:node-set($merge.ref.content)//d:info[1]"/>
+
+  <xsl:if test="$merge.element/@resourceref and not($merge.ref.info)">
+    <xsl:message terminate="yes">
+      <xsl:text>ERROR: merge element with resourceref '</xsl:text>
+      <xsl:value-of select="$merge.element/@resourceref"/>
+      <xsl:text>' must point to something with an info element.'</xsl:text>
+    </xsl:message>
+  </xsl:if>
+
+  <xsl:variable name="omittitles.boolean">
+    <xsl:choose>
+      <xsl:when test="$omittitles = 'yes' or $omittitles = 'true' or omittitles = '1'">
+        <xsl:value-of select="1"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="0"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <!-- output info if there is any -->
+  <xsl:if test="$merge.element/node() or 
+                $merge.ref.info/node() or
+                $ref.content/*/d:info/node() or
+                $ref.content/*/d:title[$omittitles.boolean = 0] or
+                $ref.content/*/d:subtitle[$omittitles.boolean = 0] or
+                $ref.content/*/d:titleabbrev[$omittitles.boolean = 0]">
+
+    <xsl:variable name="ref.info" select="$ref.content/*/d:info"/>
+    <xsl:variable name="ref.title" select="$ref.content/*/d:title"/>
+    <xsl:variable name="ref.subtitle" select="$ref.content/*/d:subtitle"/>
+    <xsl:variable name="ref.titleabbrev" select="$ref.content/*/d:titleabbrev"/>
+    <xsl:variable name="ref.info.title" select="$ref.content/*/d:info/d:title"/>
+    <xsl:variable name="ref.info.subtitle" select="$ref.content/*/d:info/d:subtitle"/>
+    <xsl:variable name="ref.info.titleabbrev" select="$ref.content/*/d:info/d:titleabbrev"/>
+
+    <info>
+      <!-- First copy through any merge attributes and elements and comments -->
+      <xsl:copy-of select="$merge.element/@*[not(local-name(.) = 'resourceref')]"/>
+
+      <!-- And copy any resource info attributes not in merge-->
+      <xsl:for-each select="$ref.info/@*">
+        <xsl:variable name="resource.att" select="local-name(.)"/>
+        <xsl:choose>
+          <xsl:when test="$merge.element/@*[local-name(.) = $resource.att]">
+            <!-- do nothing because overridden -->
+          </xsl:when>
+          <xsl:otherwise>
+            <!-- copy through if not overridden -->
+            <xsl:copy-of select="."/>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:for-each>
+
+      <!-- Copy through the merge children as they have highest priority -->
+      <xsl:copy-of select="$merge.element/node()"/>
+
+      <!-- and copy through those merge resource elements not in merge element -->
+      <xsl:for-each select="$merge.ref.info/node()">
+        <xsl:variable name="resource.node" select="local-name(.)"/>
+        <xsl:choose>
+          <xsl:when test="$merge.element/node()[local-name(.) = $resource.node]">
+            <!-- do nothing because overridden -->
+          </xsl:when>
+          <xsl:otherwise>
+            <!-- copy through -->
+            <xsl:copy-of select="."/>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:for-each>
+
+      <!-- And copy any module's resource info node not in merge or merge.ref -->
+      <xsl:for-each select="$ref.info/node() | 
+                            $ref.title[$omittitles.boolean = 0] |
+                            $ref.subtitle[$omittitles.boolean = 0] |
+                            $ref.titleabbrev[$omittitles.boolean = 0] |
+                            $ref.info.title[$omittitles.boolean = 0] |
+                            $ref.info.subtitle[$omittitles.boolean = 0] |
+                            $ref.info.titleabbrev[$omittitles.boolean = 0]">
+        <xsl:variable name="resource.node" select="local-name(.)"/>
+        <xsl:choose>
+          <xsl:when test="$merge.element/node()[local-name(.) = $resource.node]">
+            <!-- do nothing because overridden -->
+          </xsl:when>
+          <xsl:when test="$merge.ref.info/node()[local-name(.) = $resource.node]">
+            <!-- do nothing because overridden -->
+          </xsl:when>
+          <xsl:otherwise>
+            <!-- copy through -->
+            <xsl:copy-of select="."/>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:for-each>
+
+    </info>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="d:relationships">
+  <xsl:message>
+    <xsl:text>WARNING: the &lt;relationships&gt; element is not currently </xsl:text>
+    <xsl:text>supported by this stylesheet.</xsl:text>
+  </xsl:message>
+</xsl:template>
+
+<xsl:template match="d:transforms">
+  <xsl:message>
+    <xsl:text>WARNING: the &lt;transforms&gt; element is not currently </xsl:text>
+    <xsl:text>supported by this stylesheet.</xsl:text>
+  </xsl:message>
+</xsl:template>
+
+<xsl:template match="d:filterin">
+  <xsl:message>
+    <xsl:text>WARNING: the &lt;filterin&gt; element is not currently </xsl:text>
+    <xsl:text>supported by this stylesheet.</xsl:text>
+  </xsl:message>
+</xsl:template>
+
+<xsl:template match="d:filterout">
+  <xsl:message>
+    <xsl:text>WARNING: the &lt;filterin&gt; element is not currently </xsl:text>
+    <xsl:text>supported by this stylesheet.</xsl:text>
+  </xsl:message>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xsl/assembly/topic-maker-chunk.xsl b/xsl/assembly/topic-maker-chunk.xsl
new file mode 100644 (file)
index 0000000..ccb07ea
--- /dev/null
@@ -0,0 +1,222 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:exsl="http://exslt.org/common"
+                xmlns:xlink="http://www.w3.org/1999/xlink"
+                xmlns:d="http://docbook.org/ns/docbook"
+                xmlns="http://docbook.org/ns/docbook"
+               version="1.0"
+                exclude-result-prefixes="exsl">
+
+<!-- ********************************************************************
+     $Id: topic-maker-chunk.xsl,v 1.7 2012-04-16 00:29:35 bobs Exp $
+     ********************************************************************
+-->
+
+<xsl:import href="topic-maker.xsl"/>
+
+<xsl:import href="file:///c:/xml/docbook-xsl-ns-1.75.2/xhtml/chunk-common.xsl"/>
+
+<xsl:include href="file:///c:/xml/docbook-xsl-ns-1.75.2/xhtml/chunk-code.xsl"/>
+
+<xsl:param name="root.id.suffix">-info</xsl:param>
+<xsl:param name="root.as.resourceref" select="1"/>
+
+<xsl:template match="/" priority="1">
+  <xsl:apply-templates select="/" mode="process.root"/>
+
+  <xsl:call-template name="make.assembly"/>
+
+</xsl:template>
+
+<xsl:template name="chunk-element-content">
+  <xsl:param name="content">
+    <xsl:apply-imports/>
+  </xsl:param>
+
+  <xsl:copy-of select="$content"/>
+</xsl:template>
+
+<xsl:template name="make.assembly">
+  <xsl:variable name="content">
+    <assembly xmlns:xlink="http://www.w3.org/1999/xlink">
+      <xsl:call-template name="make.resources"/>
+      <xsl:call-template name="make.structure"/>
+    </assembly>
+  </xsl:variable>
+
+  <xsl:variable name="filename">
+    <xsl:if test="$manifest.in.base.dir != 0">
+      <xsl:value-of select="$base.dir"/>
+    </xsl:if>
+    <xsl:value-of select="$assembly.filename"/>
+  </xsl:variable>
+
+  <xsl:call-template name="write.chunk">
+    <xsl:with-param name="content" select="$content"/>
+    <xsl:with-param name="filename" select="$filename"/>
+    <xsl:with-param name="indent">yes</xsl:with-param>
+  </xsl:call-template>
+
+</xsl:template>
+
+<xsl:template name="make.structure">
+  <xsl:param name="root" select="/*[1]"/>
+
+  <xsl:param name="root.resourceref">
+    <xsl:call-template name="object.id">
+      <xsl:with-param name="object" select="$root"/>
+    </xsl:call-template>
+  </xsl:param>
+
+  <xsl:choose>
+    <xsl:when test="$root.as.resourceref = 0">
+      <structure>
+        <xsl:attribute name="type">
+          <xsl:value-of select="local-name($root)"/>
+        </xsl:attribute>
+        <xsl:attribute name="xml:id">
+          <xsl:value-of select="$root.resourceref"/>
+        </xsl:attribute>
+    
+        <xsl:copy-of select="($root/d:title | $root/d:info/d:title)[1]"/>
+    
+        <!-- Put the title and info stuff in a content-only module -->
+        <module resourceref="{$root.resourceref}{$root.id.suffix}" contentonly="true"/>
+        <xsl:apply-templates select="$root/*" mode="module.list"/>
+      </structure>
+    </xsl:when>
+    <xsl:otherwise>
+      <structure>
+        <xsl:attribute name="resourceref">
+          <xsl:value-of select="$root.resourceref"/>
+        </xsl:attribute>
+
+        <output renderas="{local-name($root)}"/>
+
+        <xsl:apply-templates select="$root/*" mode="module.list"/>
+      </structure>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="*" mode="module.list">
+  <xsl:variable name="is.chunk">
+    <xsl:call-template name="chunk">
+      <xsl:with-param name="node" select="."/>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <!-- generate an output element for renderas? -->
+  <xsl:variable name="src.element" select="concat(' ', local-name(.), ' ')"/>
+
+  <xsl:variable name="is.topic">
+    <xsl:choose>
+      <xsl:when test="contains($topic.list, $src.element)">1</xsl:when>
+      <xsl:otherwise>0</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:if test="$is.chunk = 1">
+    <module>
+      <xsl:attribute name="resourceref">
+        <xsl:call-template name="object.id"/>
+      </xsl:attribute>
+
+      <xsl:if test="$is.topic = 1">
+        <output renderas="{local-name()}"/>
+      </xsl:if>
+
+      <xsl:apply-templates select="*" mode="module.list"/>
+    </module>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template name="make.resources">
+  <resources>
+    <!-- Add xml:base from $base.dir if manifest not in base.dir -->
+    <xsl:if test="string-length($base.dir) != 0 and
+                  $manifest.in.base.dir = 0">
+      <xsl:attribute name="xml:base">
+        <!-- strip off trailing slash for xml:base -->
+        <xsl:choose>
+          <xsl:when test="substring($base.dir, string-length($base.dir),1) = '/'">
+            <xsl:value-of select="substring($base.dir, 1, string-length($base.dir) -1)"/>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$base.dir"/>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:apply-templates select="/*[1]" mode="resource.list"/>
+  </resources>
+</xsl:template>
+
+<xsl:template match="*" mode="resource.list">
+  <xsl:variable name="is.chunk">
+    <xsl:call-template name="chunk">
+      <xsl:with-param name="node" select="."/>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <xsl:if test="$is.chunk = 1">
+    <resource>
+      <xsl:attribute name="fileref">
+        <!--
+        <xsl:if test="$manifest.in.base.dir = 0">
+          <xsl:value-of select="$base.dir"/>
+        </xsl:if>
+        -->
+        <xsl:apply-templates select="." mode="chunk-filename"/>
+      </xsl:attribute>
+
+      <xsl:attribute name="xml:id">
+        <xsl:call-template name="object.id"/>
+      </xsl:attribute>
+
+      <xsl:variable name="title">
+        <xsl:apply-templates select="." mode="title.markup"/>
+      </xsl:variable>
+      <xsl:if test="string-length($title) != 0">
+        <description>
+          <xsl:value-of select="$title"/>
+        </description>
+      </xsl:if>
+
+    </resource>
+  </xsl:if>
+
+  <xsl:apply-templates select="*" mode="resource.list"/>
+</xsl:template>
+
+<!-- special case for root id on structure element -->
+<xsl:template match="/*" mode="resource.list">
+  <xsl:param name="root.resourceref">
+    <xsl:call-template name="object.id">
+      <xsl:with-param name="object" select="."/>
+    </xsl:call-template>
+  </xsl:param>
+
+  <resource>
+    <xsl:attribute name="fileref">
+      <xsl:apply-templates select="." mode="chunk-filename"/>
+    </xsl:attribute>
+    <xsl:attribute name="xml:id">
+      <xsl:choose>
+        <xsl:when test="$root.as.resourceref = 0">
+          <xsl:value-of select="concat($root.resourceref,$root.id.suffix)"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$root.resourceref"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:attribute>
+  </resource>
+  <xsl:apply-templates select="*" mode="resource.list"/>
+</xsl:template>
+
+<!-- This one must be here because of the template in chunk-code.xsl -->
+<xsl:template match="@fileref" priority="1">
+    <xsl:copy-of select="."/>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xsl/assembly/topic-maker.xsl b/xsl/assembly/topic-maker.xsl
new file mode 100644 (file)
index 0000000..5e64502
--- /dev/null
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet 
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
+  xmlns:exsl="http://exslt.org/common"
+  xmlns="http://docbook.org/ns/docbook"
+  xmlns:d="http://docbook.org/ns/docbook"
+  exclude-result-prefixes="exsl"
+  version="1.0">
+
+<!-- $Id: topic-maker.xsl,v 1.3 2012-04-16 00:29:35 bobs Exp $ -->
+
+<!-- This stylesheet convert DocBook elements into topic element.
+     The chunking takes place elsewhere.  -->
+
+<xsl:import href="file:///c:/xml/docbook-xsl-ns-1.75.2/xhtml/docbook.xsl"/>
+    
+    
+<xsl:param name="assembly.filename">myassembly.xml</xsl:param>
+<xsl:param name="chunk.section.depth" select="3"/>
+<xsl:param name="chunk.first.sections" select="1"/>
+<xsl:param name="use.id.as.filename" select="1"/>
+<xsl:param name="html.ext">.xml</xsl:param> 
+<xsl:param name="base.dir">topics/</xsl:param>
+<xsl:param name="root.filename" select="local-name(/*)"/>
+<xsl:param name="html.extra.head.links" select="0"/>
+<xsl:param name="stylesheet.result.type">xhtml</xsl:param>
+<xsl:param name="navig.showtitles" select="0"/>
+<xsl:param name="suppress.navigation" select="1"/>
+<xsl:param name="chunk.append"/>
+<xsl:param name="chunk.quietly" select="0"/>
+<xsl:param name="chunker.output.method" select="'xml'"/>
+<xsl:param name="chunker.output.encoding" select="'UTF-8'"/>
+<xsl:param name="chunker.output.indent" select="'no'"/>
+<xsl:param name="chunker.output.omit-xml-declaration" select="'no'"/>
+<xsl:param name="chunker.output.standalone" select="'no'"/>
+<xsl:param name="chunker.output.doctype-public" select="''"/>
+<xsl:param name="chunker.output.doctype-system" select="''"/>
+<xsl:param name="namespace">http://docbook.org/ns/docbook</xsl:param>
+
+<!-- These elements are converted to topic elements -->
+<xsl:param name="topic.elements">preface chapter article section</xsl:param>
+<xsl:variable name="topic.list"
+              select="concat(' ', normalize-space($topic.elements), ' ')"/>
+
+<!-- Default behavior is identity copy -->
+<xsl:template match="node()|@*">
+    <xsl:copy>
+      <xsl:apply-templates select="@*"/>
+      <xsl:apply-templates/>
+   </xsl:copy>
+</xsl:template>
+
+<xsl:template match="d:preface|d:chapter|d:appendix|d:section|d:article">
+  <xsl:variable name="element.name">
+    <xsl:call-template name="element.name"/>
+  </xsl:variable>
+
+  <xsl:element name="{$element.name}" namespace="{$namespace}">
+    <xsl:apply-templates select="@*"/>
+    <xsl:apply-templates/>
+  </xsl:element>
+</xsl:template>
+
+<xsl:template name="element.name">
+  <xsl:param name="node" select="."/>
+
+  <xsl:variable name="src.element" select="concat(' ', local-name($node), ' ')"/>
+  <xsl:choose>
+    <xsl:when test="contains($topic.list, $src.element)">
+      <xsl:text>topic</xsl:text>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="local-name($node)"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
+