Edit online

It is possible to dynamically change an image in the header depending on the chapter. For this, you need to define an image reference in the metadata section of each chapter. One way is to specify it in the DITA map by using the <topicmeta> element for the <chapter> topic reference:

...
 <chapter href="topics/installing.dita">
    <topicmeta>
      <data name="header-image" value="img/installing.png"/>
    </topicmeta>
    ...

In the above example, there is set of key value pairs with the name header-image. The img/installing.png is an image reference relative to the DITA map URI. This information is automatically copied into the content in the merged map file, like this:

<topic is-chapter="true" ... >
    <title class="- topic/title ">Installing</title>
    <shortdesc class="- topic/shortdesc ">You install components to make them available for your
      solution.</shortdesc>
    <prolog class="- topic/prolog ">
      ...
      <data class="- topic/data " name="header-image" value="img/installing.png"/>
      ...

This information can be picked up from CSS:

/* Define the string set variable that contains an URL */
*[class ~= "topic/topic"] *[class ~= "topic/data"][name="header-image"] {
  string-set: imgst oxy_url(oxy_xpath('/*/@xtrf'), attr(value));
}

/* Using the value='none' stops applying the image. */
*[class ~= "topic/topic"] *[class ~= "topic/data"][name="header-image"][value="none"] {
  string-set: imgst "";
}

/* Use the string set variable in one of the page margin boxes. */
@page chapter {  
  @top-left-corner {
    content: string(imgst);
    font-size:0; /* remove the font ascent and descent */
  }
}

Details: The @value attribute is used to build a URL relative to the URI of the DITA map. To determine the base URI of the DITA map, the @xtrf attribute was used from the root element of the merged map document, extracted using the oxy_xpath function.

Notes:
  • The image is always aligned vertically to the middle of available space from the page margin box.
  • Make sure you use an image of the correct size. For example, if you want to place the image in the top-left corner of the page, assuming the top and left page margins are 1 in, then make sure the image is a square having a size of 1 in.
  • The image is applied to all pages that follow the data element, until another data element changes it:
    ...
     <chapter href="topics/installing.dita">
        <topicmeta>
          <data name="header-image" value="img/installing.png"/>
        </topicmeta>
     </chapter>
     <chapter href="..."> <!-- Uses the same installing.png image -->
     <chapter href="..."> <!-- Uses the same installing.png image -->
     <chapter href="..."> <!-- Uses the same installing.png image -->
     <chapter href="topics/change.dita">
        <topicmeta>
          <data name="header-image" value="img/change.png"/>
        </topicmeta>
     </chapter>
     <chapter href="..."> <!-- Uses the same change.png image -->
     <chapter href="..."> <!-- Uses the same change.png image -->
     <chapter href="..."> <!-- Uses the same change.png image -->
    
    To clear the image, use the none value:
    ...
          <data name="header-image" value="none"/>
     ...