Graphic Map Generation

The map-driven processing generates an Ant script that copies graphics or other resources from their source locations to the output location.

Because the map-driven processing allows you to change the output organization of the generated files, references to graphics and other resources in the source DITA XML do not translate directly to references in the output. To address this, the map-driven process finds all graphic references in the input data (including graphics referenced from DITAVAL files), constructs an input-to-output location map, and generates an Ant script that copies the source graphics to their output location. As part of output generation, references to graphics are rewritten to reflect their output location. This process can be extended to include any kind of resource, such as Javascript, CSS, static graphics, etc. However, it does not modify references in non-DITA files, such as CSS style sheets. (This is most useful for EPUB output. For HTML5 output there is a separate feature for managing all the Web-specific theme components.)

The graphic map generation is implemented in the module org.dita4publishers.common.xslt/xsl/map2graphicMap.xsl. You can extend the default processing to provide mapping for any graphics that are not represented by normal DITA markup, such as covers determined by run-time parameters or branding graphics defined separately or whatever.

The map generation is done in two phases.

The first phase is mode "get-graphic-refs", which is applied to the map, all topics, the OT-generated "image.list" file and the DITAVAL file, if specified. It results in a set of graphic reference elements of the form:
   href="{absoluteUrl of source graphic}" 
   filename="{filename of the graphic}"

One <graphic-ref> element should be generated for each graphic reference in the source.

You can add additional graphic map items using the mode "additional-graphic-refs", which is applied to the root map. Templates in this mode must produce <gmap:graphic-ref> elements that point to the source location of the item to be included. See the templates in the map2epubEmbedFonts.xsl in the org.dita4publishers.epub plugin for example code.

You can override or extend the image.list processing using the mode "map2graphicmap:handleImageListFile". The context items for the templates in this mode are text nodes, one for each line of the image.list file. The result of a match on an image list item must be a <gmap:graphic-map-item> element that specifies the input and output URIs for the image. See the base template in map2graphicMap.xsl. You can use this mode to map source graphic filenames to some other name or to otherwise augment the set of graphics to copy based on details of the image list.

The second phase processes all the <graphic-ref> elements to determine the set of unique graphics used. This process results in the graphic map, which looks like this:
<?xml version="1.0" encoding="UTF-8"?>

The graphic map may then be passed as a parameter to subsequent processing and is used to generate the copy-graphics.xml Ant script (mode "generate-graphic-copy-ant-script" implemented in module org.dita4publishers.common.xslt/xsl/graphicMap2AntCopyScript.xsl).

Image URLs are rewritten during initial topic processing using the mode "href-fixup" implemented in the module org.dita4publishers.common.xslt/xsl/topicHrefFixup.xsl. URLs are rewritten to reflect the output location of the images so that the default HTML output processing will automatically construct the correct URL for the images.