Adding New fm-ditabook Attributes

Passing metadata from a DITA map to the generated FM book file can be accomplished by creating new attributes on the fm-ditabook element.

Two DITA-FMx features read the attribute values on the fm-ditabook element (the root of a generated book file). These attributes can define values that are passed to the book components as FrameMaker variables. These attributes can also be used to control the show/hide state of conditions in the generated book components. For information on enabling these features see the ImportAttrsAsVars, and ImportAttrsAsConds parameter information in Book-Build INI file.

In order to add your own attributes to the fm-ditabook element, you need to modify a number of files in the Book structure application. The following is an overview of the steps required; details are provided below.

  1. Modify the EDD to add attributes to the fm-ditabook element definition.
  2. Import the updated EDD into the Book template.
  3. Modify the fmxbook.dtd file to add the new attribute definitions.
  4. Modify the bookmap2fmbook.xsl file to copy the desired metadata (attributes or other content) into the new fm-ditabook attributes.

Specific information regarding the modification of the DTD and XSL files are provided below.

Modifying the fmxbook.dtd file

The fmxbook.dtd file is found in the Book application’s dtd folder.

  1. Open the fmxbook.dtd file and locate the attribute definitions for the fm-ditabook element. The unaltered attribute definition should look like the following.

    <!ATTLIST fm-ditabook 
        href CDATA #IMPLIED 
        format CDATA #IMPLIED 
        title CDATA #IMPLIED 
    >
  2. Add the new attributes. The example below adds a new “version” attribute.

    <!ATTLIST fm-ditabook 
        href CDATA #IMPLIED 
        format CDATA #IMPLIED 
        title CDATA #IMPLIED 
        version CDATA #IMPLIED 
    >
  3. Save and close the DTD file.

Modifying the bookmap2fmbook.xsl file

The bookmap2fmbook.xsl file is used to aggregate the DITA topics into a book file and component FM files. It can be used to copy data from the DITA map into attributes of the fm-ditabook element. Most likely you would copy data from the bookmeta or topicmeta elements, but any accessible element or attribute data could be used.

  1. Open the bookmap2fmbook.xsl file in a text editor. Near the top of the file in a “START VARIABLES” section, you’ll see code that defines a variable for each metadata item. (These variable definitions follow an XML comment of “General Content variables to access metadata ...”.) For example, the following variable definition sets the “created” variable from the first critdates/created/@date attribute in the map.

    <xsl:variable name="created"> 
      <xsl:value-of select="translate(//critdates/created[1]/@date, '&#10;', ' ')"/> 
    </xsl:variable>

    You’ll need to add a similar variable definition for any new metadata that you want to extract from the map. Note that even if you don’t expect there to be more than one instance of a metadata value, it’s a good practice to explicitly select the first (or last) value, just in case there are more than one in a file you’re processing.

  2. Locate the map and/or bookmap templates. It will depend on the type of data you’re copying as to which template you will work on. The map and bookmap templates begin with the following lines.

    <xsl:template mode="final" match="map"> 
    ... 
    </xsl:template> 
     
    <xsl:template mode="final" match="bookmap"> 
    ... 
    </xsl:template>
  3. Within each template is code that creates the fm-ditabook element, and within the fm-ditabook block is code that sets the values extracted from the map to attribute values. Add your new code after the existing attribute code.

    <xsl:template mode="final" match="map"> 
    ... 
      <fm-ditabook xsl:exclude-result-prefixes="ditaarch"> 
    ... 
        <xsl:attribute name="created"> 
          <xsl:value-of select="$created"/> 
        </xsl:attribute> 
    ... 
        <xsl:apply-templates mode="final"/> 
      </fm-ditabook> 
    ... 
    </xsl:template>
  4. Save and close the XSL file.