Tecnologías XML / XSL-FO / Ejemplos de aplicación / Bloques de texto

 

Bloques de texto

Se crean bloques de texto con propiedades controladas por el documento de instancia.

Este ejemplo presenta una plantilla para crear bloques de texto. Estos bloques pueden formatearse con atributos de la instancia que especifican tamaño, alineación, sangría, negrita, cursiva y otras propiedades.

Extracto de DTD:

<!ELEMENT TB (#PCDATA | ...)*>
<!ATTLIST TB
     Groesse (normal | gross | klein) "normal"
     Schrift (normal | fett | kursiv) "normal"
     Aliniierung (links | rechts | mittig | block) "block"
     EinzugLinks (ohne | mit | Zeile1 | haengend) "ohne">

Hoja de estilo:

<xsl:template match="TB"> 
    <fo:block text-align="justify" hyphenate="true" xml:lang="de"                 ❶
    margin-left="10mm">         
       <xsl:choose>
          <xsl:when test="@Groesse='gross'">                                      ❷
             <xsl:attribute name="font-size">14pt</xsl:attribute>                 ❸
          </xsl:when>
          <xsl:when test="@Groesse='klein'"> 
             <xsl:attribute name="font-size">10pt</xsl:attribute>
          </xsl:when> 
          <xsl:otherwise>                                                         ❹   
             <xsl:attribute name="font-size">12pt</xsl:attribute>
           </xsl:otherwise>
        </xsl:choose>
        <xsl:choose>
           <xsl:when test="@Schrift='fett'">                                      ❺
               <xsl:attribute name="font-weight">bold</xsl:attribute>
           </xsl:when>
           <xsl:when test="@Schrift='kursiv'">
              <xsl:attribute name="font-style">italic</xsl:attribute>
           </xsl:when> 
           <xsl:otherwise/>                                                       ❻
        </xsl:choose>
        <xsl:choose>
           <xsl:when test="@Aliniierung='links'">
              <xsl:attribute name="text-align">left</xsl:attribute>
           </xsl:when>
           <xsl:when test="@Aliniierung='rechts'"> 
              <xsl:attribute name="text-align">right</xsl:attribute>
           </xsl:when>
           <xsl:when test="@Aliniierung='mittig'">
              <xsl:attribute name="text-align">center</xsl:attribute>
           </xsl:when>
           <xsl:otherwise>
              <xsl:attribute name="text-align">justify</xsl:attribute>
           </xsl:otherwise>
        </xsl:choose>
        <xsl:choose> 
           <xsl:when test="@EinzugLinks='mit'">
              <xsl:attribute name="margin-left">15mm</xsl:attribute>
           </xsl:when> 
           <xsl:when test="@EinzugLinks='Zeile1'">
              <xsl:attribute name="text-indent">10mm</xsl:attribute>
           </xsl:when> 
           <xsl:when test="@EinzugLinks='haengend'">
              <xsl:attribute name="text-indent">-10mm</xsl:attribute> 
           </xsl:when>
           <xsl:otherwise/>
       </xsl:choose>
       <xsl:apply-templates/>
   </fo:block>
</xsl:template>

 

❶ Para el bloque se definen atributos generales: justificación, división alemana y sangría izquierda.

❷ Los demás ajustes dependen de atributos y valores, mediante el mecanismo XSLT con <xsl:choose>.

❸ La condición de tamaño gross fija el tamaño en 14pt.

❹ La condición de tamaño normal, o la ausencia del atributo que usa su valor predeterminado, fija el tamaño en 12pt.

❺ La explicación del tamaño se aplica análogamente.

❻ También se aplica la explicación del tamaño predeterminado, pero aquí no se especifica atributo, así que <xsl:otherwise> queda vacío.

 

<< atrás

siguiente >>

volver arriba