bridgehead
Elements into section
ElementsYou have a DocBook document which contains several
bridgehead
elements. The bridgehead
has to
be transformed into the correct section
structure.
A bridgehead
element is a “free-floating
heading”. In most cases it is a bad idea as it is
difficult to handle in XSLT. To create the correct section
hierarchy, a stylesheet need to collect all nodes between a
bridgehead
element and the next one. The following
stylesheet uses a set difference method:
The solution is unfortunately not very trivial in XSLT 1.0.
The template rule d:section[d:bridgehead]
matches
only section
s which contain one or more
bridgehead
elements.
The
template rule performs the following steps:
Collect all nodes inside a section
and save it
in variable node1
.
Collect all nodes who follows the next
bridgehead
including the next
bridgehead
itself and save it in variable
node2
.
Creates a section
element and copy all
attributes from the bridgehead
element.
Creates a title
element and apply the content
from the bridgehead
element. This copies the
content from bridgehead
.
Calculates the set difference between
node1
and node2
. This
weird expression is needed in XSLT 1.0 to create a node set
which contains only those nodes up to the first
bridgehead
.
Handle the first bridgehead
element which is
covered by our bridgehead
template rule.
The bridgehead
template rule is responsible for
transforming the current bridgehead
element into a
section
. It is also responsible for the next
bridgehead
s. The rule performs the following
steps:
Collect all nodes following of the current
bridgehead
element and save it in variable
node1
.
Collect all nodes following of the next
bridgehead
element including the next
bridgehead
element itself. Save the node set in
variable node2
.
Creates a section
element and copy all
attributes from the bridgehead
element.
Creates a title
element and apply the content
from the bridgehead
element. This copies the
content from bridgehead
.
Calculate the set difference between
node1
and node2
and
apply the correct template rule (usually they are just
copied).
Close the section
element and handle the next
bridgehead
element.
Project@GitHub | Issue#8 |