[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] make an fo:table with XSLT from an xml file


Subject: RE: [xsl] make an fo:table with XSLT from an xml file
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Wed, 7 Jul 2004 08:22:24 +0300

Hi,

> here is a sample of my xml file that I want to convert in pdf 
> by using fop.
> 
> <row>
>    <cell>
>        <para column="1" line="1">Session</para>
>    </cell>
>    <cell>
>        <para column="2" line="1">Name</para>
>        <para column="2" line="2">LAP</para>
>    </cell>
> </row>
> 
> the result must be (it is an extract):

Something in the lines of

  <xsl:template match="row">
    <fo:page-sequence master-reference="A4">
      <fo:flow flow-name="xsl-region-body" font-family="sans-serif" font-size="12pt">
        <fo:table border="solid black">
          <fo:table-header text-align="center" font-weight="bold" background-color="silver">
            <xsl:call-template name="row">
              <xsl:with-param name="count">
                <xsl:for-each select="cell/para">
                  <xsl:sort select="@column" data-type="number" order="descending"/>
                  <xsl:if test="position() = 1">
                    <xsl:value-of select="@column"/>
                  </xsl:if>
                </xsl:for-each>
              </xsl:with-param>
            </xsl:call-template>
          </fo:table-header>
        </fo:table>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>
  <xsl:template name="row">
    <xsl:param name="line" select="1"/>
    <xsl:param name="count" select="0"/>
    <xsl:if test="cell/para[@line = $line]">
      <fo:table-row border-bottom="solid black">
        <xsl:call-template name="col">
          <xsl:with-param name="cells" select="cell/para[@line = $line]"/>
          <xsl:with-param name="count" select="$count"/>
        </xsl:call-template>
      </fo:table-row>
      <xsl:call-template name="row">
        <xsl:with-param name="line" select="$line + 1"/>
        <xsl:with-param name="count" select="$count"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="col">
    <xsl:param name="cells" select="/.."/>
    <xsl:param name="index" select="1"/>
    <xsl:param name="count" select="0"/>
    <xsl:if test="$index &lt;= $count ">
        <fo:table-cell padding="1mm" border-left="solid black">
          <fo:block>
            <xsl:value-of select="$cells[@column = $index]"/>
          </fo:block>
        </fo:table-cell>
      <xsl:call-template name="col">
        <xsl:with-param name="cells" select="$cells"/>
        <xsl:with-param name="index" select="$index + 1"/>
        <xsl:with-param name="count" select="$count"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

Cheers,

Jarno - Lisa Lashes: Hard Mix


Current Thread
Keywords
xml