Search code examples
xsl-foapache-fop

`retrieve-marker` in attribute value


I'm trying to use a marker to determine the image to show in a header/footer. Each chapter has a marker which communicates the image to use. When I use <fo:marker / <fo:retreive-marker in an <xsl:attribute element, it understandably produces an invalid src= value.

e.g. pages:

  1. Chapter 1
  2. Chapter 1 ends; chapter 2 begins
  3. Chapter 2

Header for page 1 and 2 would reference <external-graphic src="1.png"/> and 3 would reference <external-graphic src="2.png"/>.

How can I embed an image in a header or footer that varies based on the flow content?


Solution

  • An fo:marker could contain just text, but you can't retrieve that text to make the value of a src property.

    What would work is to retrieve an entire fo:external-graphic that has the correct src value. Something like (untested):

    <fo:page-sequence master-reference="...">
      <fo:marker marker-class-name="image">
        <fo:external-graphic src="1.png"/>
      </fo:marker>
      <fo:static-content flow-name="xsl:region-after">
        <fo:block><fo:retrieve-marker retrieve-class-name="image"/></fo:block>
      </fo:static-content>
      <!-- Stuff -->
    </fo:page-sequence>
    <fo:page-sequence master-reference="...">
      <fo:marker marker-class-name="image">
        <fo:external-graphic src="2.png"/>
      </fo:marker>
      <fo:static-content flow-name="xsl:region-after">
        <fo:block><fo:retrieve-marker retrieve-class-name="image"/></fo:block>
      </fo:static-content>
      <!-- More stuff -->
    </fo:page-sequence>