Search code examples
xsltxsl-foapache-fop

How to create black rectangles with white words in XSL?


I want to create a white text inside a black rectangle but what do I have to add to my code to achieve that? I want Departure to be white in a black rectancle.

<fo:block>
         <fo:table>
              <fo:table-column column-width="20%"/>
              <fo:table-column column-width="20%"/>
  <fo:table-column column-width="20%"/>
  <fo:table-column column-width="20%"/>
  <fo:table-column column-width="20%"/>
                                    <fo:table-body>
                    <fo:table-row>

    <fo:table-cell>
                          <fo:block font-size = "10">DEPARTURE</fo:block>
                          </fo:table-cell>

                          <fo:table-cell>
                <fo:block font-size="4"   text-align="center" >ROUTE</fo:block>
    <fo:block font-size="6" text-align="center">$ROUTE</fo:block>
    </fo:table-cell>

    <fo:table-cell>
    <fo:block  font-size="4"   text-align="center">RATE</fo:block>
    <fo:block  font-size="6"   text-align="center">$RATE</fo:block>
    </fo:table-cell>

    <fo:table-cell>
    <fo:block  font-size="4"   text-align="center">DEPARTURE DATE</fo:block>
    <fo:block  font-size="6"   text-align="center">$DEPARTUREDATE</fo:block>
    </fo:table-cell>

    <fo:table-cell>
    <fo:block  font-size="4"   text-align="center">DEPARTURE TIME</fo:block>
    <fo:block  font-size="6"   text-align="center">$DEPARTURETIME</fo:block>
    </fo:table-cell>

                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:block>

Solution

  • Try

    <fo:block font-size="10" background-color="#000000" color="#ffffff">DEPARTURE</fo:block>
    

    I think you'd likely also add a font-weight="bold" then. Free Advice: <fo:block font-size="6" text-align="center">$DEPARTURETIME</fo:block> looks like not-what-you-want-xslt, but probably <fo:block font-size="6" text-align="center"><xsl:value-of select="$DEPARTURETIME"></fo:block>