Hi Ilan,
I know of two approaches to this problem.
In the first approach, in your customization layer process the
requirement element into docbook table elements inside a variable,
convert the variable's content to a node-set using the exlt:node-set()
function, and then process the node-set with the standard DocBook
stylesheets (see example below).
or
Preprocess your document into a temporary document with a stylesheet
that is an identity stylesheet except for templates that process
requirements into DocBook tables. The output is a pure DocBook
document, mixing your original DocBook elements copied over with the
generated DocBook tables. Then you can process this temporary document
with standard DocBook stylesheets.
The first approach has the advantage of being done in a single XSLT
process, because the table is held in memory and then processed, while
the second approach requires two XSLT processes. The second approach
has the advantage of transparency, in that you can view the temporary
output to see how it is working, while an internal node-set is not visible.
Here is an example of the first approach that works for HTML processing,
using a much simpler input element and link:
<requirement xml:id="myrequirement">
<firstthing>My requirement</firstthing>
</requirement>
...
<link linkend="myrequirement">Link to Requirement</link>
and the template that processes that (I'm assuming you are using DocBook 5):
<xsl:template match="d:requirement">
<xsl:variable name="id" select="@xml:id"/>
<xsl:variable name="req">
<d:informaltable>
<xsl:attribute name="xml:id">
<xsl:value-of select="$id"/>
</xsl:attribute>
<d:tgroup cols="1">
<d:tbody>
<d:row>
<d:entry>
<xsl:value-of select="d:firstthing"/>
</d:entry>
</d:row>
</d:tbody>
</d:tgroup>
</d:informaltable>
</xsl:variable>
<xsl:variable name="nodeset" select="exsl:node-set($req)"/>
<xsl:apply-templates select="$nodeset"/>
</xsl:template>
I used d:informaltable to avoid table numbering, because requirement
won't be counted as a table so the numbering sequence won't be right
(unless you fix the template that counts tables). Since you didn't
include a title, I assumed you meant informaltable anyway. If you want
these things numbered along with your other tables, you will have to use
the second approach.
Also, the nodeset approach won't work for FO output because the
informaltable in the nodeset is treated as a separate document, and so
the stylesheet will generate fo:root for the table within a
fo:page-sequence, which is invalid in the XSL-FO processor.
If you use the second, two-pass approach, a single first-pass stylesheet
can generate the temporary pure DocBook document for either HTML or FO
processing, so I would recommend that approach. Let me know if you need
more help with the identity stylesheet approach.
Bob Stayton
Sagehill Enterprises
b...@sagehill.net
On 12/10/2018 5:44 AM, Ilan Finci wrote:
Hi
I’m new to docbook and XSLT, and tried to find the answer among the
different books/websites and failed, so looking up for your help
(pointers to the right place will be good as well).
I’m trying to add a new element to my docbook, that will describe a
requirement for example:
<requirement>
<req_id>TRC_001</req_id>
<version>1</version>
<status>New</status>
<priority>H</priority>
<description>We need to be able to save a snapshot of requirements per
product version</description>
<traceability>None</traceability>
</requirement>
In my outputs, I want to format each such requirement as a table.
Writing same table as docbook table directly, I would have something like:
<table>
<tgroup cols="4">
<colspec colnum="1" colname="1"
colwidth="*" />
<colspec colnum="2" colname="3"
colwidth="*" />
<colspec colnum="3" colname="3"
colwidth="*" />
<colspec colnum="4" colname="4"
colwidth="*" />
<spanspec spanname="desc" namest="1"
nameend="3"/>
<tbody>
<row>
<entry><para>TRC_001</para> </entry>
<entry><para>1</para> </entry>
<entry><para>New</para></entry>
<entry><para>H</para></entry>
</row>
<row>
<entry spanname="desc"><para> We need to be able to
save a snapshot of requirements per product version </para></entry>
<entry colname="4"><para>None</para></entry>
</row>
</tbody>
</tgroup>
</table>
I tried to add this to stylesheet, but I cannot write “docbook” table
there, and I have to do it per output format (HTML – use the tr & td
flags, FO for PDF and other print formats…)
1. Is there a way to do the conversion of the new “requirement” into
docbook code, which will automatically be formatted as HTML or FO
later, base on the xsltproc parameters I give?
2. Is there a way to add reference based on the requirement ID (so I
can link to it later)?
Thanks in advance
Ilan
IMPORTANT NOTICE: The contents of this email and any attachments are
confidential and may also be privileged. If you are not the intended
recipient, please notify the sender immediately and do not disclose
the contents to any other person, use it for any purpose, or store or
copy the information in any medium. Thank you.