Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

software for linux - transform xml using xsl to pdf

Tags:

html

xml

pdf

xslt

I have two files.

I want to create pdf with these two files.

  1. does anyone know program on linux that can do that?
  2. whats the command?

The first one is xhtml/xml file:

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<table border="1">
    <tr>
        <td>Day/Time</td>
        <td>7.30</td>
        <td>8.15</td>
        <td>9.05</td>
        <td>9.50</td>
        <td>10.40</td>
        <td>11.25</td>
        <td>12.15</td>
        <td>13.00</td>
        <td>13.50</td>
        <td>14.35</td>
        <td>15.25</td>
        <td>16.10</td>
        <td>17.00</td>
        <td>17.45</td>
        <td>18.35</td>
    </tr>
    <tr>
        <td>Monday</td>
        <td colspan="4"></td>
        <td colspan="2">UvIn 134 1.P</td>
        <td colspan="3">Mult 134 3.P -> 137</td>
        <td colspan="6"></td>
    </tr>
    <tr>
        <td>Tuesday</td>
        <td colspan="2">InTe 135 1.P</td>
        <td></td>
        <td colspan="3">MaAn 336 1.P</td>
        <td></td>
        <td colspan="2">AlSu 134 1.P</td>
        <td colspan="2"></td>
        <td colspan="2">AlSu 135 1.P</td>
        <td colspan="2"></td>
    </tr>
    <tr>
        <td>Wednesday</td>
        <td colspan="2"></td>
        <td colspan="3">Kart 134 2.PV</td>
        <td colspan="2">INTE 041 2.PV</td>
        <td></td>
        <td colspan="2">Aj 139 1.P</td>
        <td colspan="5"></td>
    </tr>
    <tr>
        <td>Thursday</td>
        <td colspan="2"></td>
        <td colspan="2">GeIn 139 2.PV</td>
        <td colspan="3">SePr 135 1.P</td>
        <td colspan="8"></td>
    </tr>
    <tr>
        <td>Friday</td>
        <td colspan="15"></td>
    </tr>
</table>
</body>
</html>

and the second one is .xsl file - combined xslt+xsl-fo:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:a="http://www.w3.org/1999/xhtml">
  <xsl:template match="a:html">
    <fo:root>
      <fo:layout-master-set>
        <fo:simple-page-master master-name="a4">
          <fo:region-body padding-top="1in" padding-left="1.5mm" background-color="#222"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <xsl:apply-templates/>
    </fo:root>
  </xsl:template>

  <xsl:template match="a:body">
    <fo:page-sequence master-reference="a4">
      <fo:flow flow-name="xsl-region-body">
        <fo:table>
          <fo:table-body background-color="#333">
            <xsl:for-each select="a:table/a:tr">
              <fo:table-row>
                <xsl:for-each select="a:td">
                  <fo:table-cell padding="0.5mm" border-width="2mm" border-style="outset" border-color="#bbb" color="#aaff00" font-weight="bold" font-family="arial" text-align="center">
                    <xsl:if test="@colspan"><xsl:attribute name="number-columns-spanned"><xsl:value-of select="@colspan"/></xsl:attribute></xsl:if>
                    <xsl:value-of select="."/>
                  </fo:table-cell>
                </xsl:for-each>
              </fo:table-row>
            </xsl:for-each>
          </fo:table-body>
        </fo:table>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>
</xsl:stylesheet>
like image 579
Milan Rusko Avatar asked Feb 04 '26 04:02

Milan Rusko


1 Answers

You'll need an XSLT processor, xsltproc is probably already in your Linux distribution. Then you'll need a processor to convert the FO (Formatting Objects) to a PDF. Apache has a free FO processor (FOP): Apache™ FOP: Downloading A Distribution

Once you have a FOP downloaded and extracted, your pipeline might look something like this:

$ xsltproc so.xsl so.xml > so.fo
$ <path-to-extracted-fop-dir>/fop so.fo so.pdf

I've tried as much with your provided XML source and XSLT, and there were errors when running Apache FOP. I don't know anything about your XSLT, so you might be able to get around the errors.

like image 149
Zach Young Avatar answered Feb 05 '26 20:02

Zach Young



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!