2

I'm writing some documentation using docbook maven plugin and I'm looking for making a navigation bar in the header of the HTML output automatically.

I have some books organized like this :

  • Guide1
  • Guide2
  • Tutorials
    • tuto1
    • tuto2

The desired result is to generate a navigation bar in the HTML output with for each book using XSL stylesheet. Something like :

<xsl:template name="user.header.content">
  <xsl:for-each select="something">
      <xsl:value-of select="somethingelse"/>
  </xsl:for-each>
</xsl:template>

Thanks in advance :).

Mohammed
  • 115
  • 1
  • 13
  • Could you give an exemple of your xml input, and the desired xml output ? – Istao Mar 28 '13 at 14:31
  • Xml input are my guides each one is a [book](http://www.docbook.org/tdg/en/html/book.html). All of them use a xsl stylesheet file wich customize the HTML output. I would like to retrieve some informations (id/title of each book) from the xsl stylesheet. For information, I use the docbook maven plugin and include files are files which the name match *-guide.xml. – Mohammed Mar 28 '13 at 14:40

2 Answers2

0

Use the standard XSLT function document().

Example:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xsl:output method="text"/>

 <xsl:template match="/">
  <xsl:value-of select=
  "document('http://www.w3.org/2007/schema-for-xslt20.xsd')
     /*/xs:annotation[1]/xs:documentation
  "/>
 </xsl:template>
</xsl:stylesheet>

When this transformation is applied on any XML document (not used), it accesses the XML document at the specified URL (this is the XSD for the XSLT 2.0 language) and outputs the string value of the first xs:annotation/xs:documentation element of this remote XML document:

This is a schema for XSLT 2.0 stylesheets.

It defines all the elements that appear in the XSLT namespace; it also
provides hooks that allow the inclusion of user-defined literal result elements,
extension instructions, and top-level data elements.

The schema is derived (with kind permission) from a schema for XSLT 1.0 stylesheets
produced by Asir S Vedamuthu of WebMethods Inc.

This schema is available for use under the conditions of the W3C Software License
published at http://www.w3.org/Consortium/Legal/copyright-software-19980720

The schema is organized as follows:

PART A: definitions of complex types and model groups used as the basis 
        for element definitions
PART B: definitions of individual XSLT elements
PART C: definitions for literal result elements
PART D: definitions of simple types used in attribute definitions

This schema does not attempt to define all the constraints that apply to a valid
XSLT 2.0 stylesheet module. It is the intention that all valid stylesheet modules 
should conform to this schema; however, the schema is non-normative and in the event 
of any conflict, the text of the Recommendation takes precedence.

This schema does not implement the special rules that apply when a stylesheet
has sections that use forwards-compatible-mode. In this mode, setting version="3.0"
allows elements from the XSLT namespace to be used that are not defined in XSLT 2.0.

Simplified stylesheets (those with a literal result element as the outermost element)
will validate against this schema only if validation starts in lax mode.

This version is dated 2007-03-16
Authors: Michael H Kay, Saxonica Limited
         Jeni Tennison, Jeni Tennison Consulting Ltd.

2007-03-15: added xsl:document element
            revised xsl:sequence element
            see http://www.w3.org/Bugs/Public/show_bug.cgi?id=4237         

Do Note:

In case the XML documents to be accessed reside in local files, use the "file:" schema like this:

'file:///c:/temp/myXmlDocument.xml'

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
0

In my experience the best way of making documentation available via web browser is by maven-site-plugin.

maven-site-plugin lets you generate a site and then publish it to the URL specified in the <distributionManagement> section of the POM.

You may write your "navigation bar" in the index.html by editing (in the wiki-like APT format) the relative index.apt:

+- src/
   +- site/
      +- apt/
      |  +- index.apt

Then generating the site:

+- target/
   +- site/
      +- index.html
      +- resources/
         +- Guide1.html
         +- Guide2.html
         +- tuto1.html
         +- tuto2.html
         +- Guide1.pdf
         +- Guide2.pdf
         +- tuto1.pdf
         +- tuto2.pdf

is achievable by the Maven way:

  • create a project with two sub projects (Maven modules): i.e. my-prj-doc, my-prj-site
  • my-prj-doc builds the DocBook documentation by docbkx-maven-plugin. The main artifact of this project should be the my-prj-doc-1.0.0.jar that will be installed in your local Maven repository (.m2 directory)
  • my-prj-site generates the site by maven-site-plugin; moreover by the maven-dependency-plugin (eventually attached to site phase) gets from your local Maven repository the my-prj-doc-1.0.0.jar and unpacks it into target/site/resources/ directory

My experience has proven that this way is one of the best one because gives:

  • decoupling - Read documentation and browsing it are separate concepts, and you can reflect that in separate projects and processes
  • maintainability - Working on separate projects is less error-prone
  • modularization - For short: if you start thinking documentation as code you could package and distribute documentation as an API; i.e. you could write a FAQ Maven sub project and then you could import the faq-1.0.0.jar artifact in your Guide1 and Guide2 Maven sub projects, so mantaining a single FAQ sub project you'll have the same FAQ in two (or more) different final documents.
taringamberini
  • 2,719
  • 21
  • 29