Graphics and images

In this example a graphic is integrated.

It shows how external graphics can be embedded and dimensioned regarding their heights and widths.

Excerpt from the DTD:

<!ELEMENT Graphic EMPTY>                                ❶ 
<!ATTLIST Graphic
          File ENTITY #REQUIRED                         ❷
          Width CDATA #IMPLIED                          ❸
          Height CDATA #IMPLIED>                        ❸

❶ Graphics are external, non-XML entities.

❷ The graphics have to be defined as entities in the Doctype Declaration.

❸ The height and width indications can be added as attribute values.


<xsl:template match="Graphic">
   <fo:block>                                                        ❶    
      <fo:external-graphic src="{unparsed-entity-uri(@File)}">       ❷
         <xsl:attribute name="content-width">                        ❸
            <xsl:value-of select="@Width"/>                          ❸
         <xsl:attribute name="content-height">                       ❹
            <xsl:value-of select="@Height"/>                         ❹

❶ The graphic has to be embedded in a block. In this block the alignment and border specifications are added if required.

❷ Within the <fo:external-graphic> element reference is made to the graphic to be embedded with the src (source) attribute. This source is indicated as attribute value of File. Since this attribute value is an ENTITY, it has to be inserted into the function unparsed-entity-uri(). If the graphics in the DTD are not declared as ENTITY objects, the path and the file name are indicated as attribute value to src, e.g. src="{Graphics/Example.jpg}". When using a relative path, the starting point is the textual XML instance. Please note the curly brackets!

❸ With the content-width attribute the width of the graphic can be determined. The <xsl:attribute> element generates an attribute in the <fo:external-graphic> element with the name of the value indicated in the name attribute, in this example the content-width attribute. The value of the attribute is read out from the Width attribute by the <xsl:value-of> element.

❹ The content-height attribute determines the height of the graphic. If only one of the attributes content-height or content-width is specified in the instance, the graphic is automatically scaled in both dimensions. If both attributes are scaled but do not match with the measures of the graphic file, distortions will occur when adjusting the measures.

<< back next >>

Copyright © dpunkt.verlag GmbH 2004
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSL-FO in der Praxis" ("XSL-FO in practice") is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399,