Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html linux软件-使用xsl将xml转换为pdf_Html_Xml_Xslt_Pdf - Fatal编程技术网

Html linux软件-使用xsl将xml转换为pdf

Html linux软件-使用xsl将xml转换为pdf,html,xml,xslt,pdf,Html,Xml,Xslt,Pdf,我有两个文件 我想用这两个文件创建pdf 有人知道linux上的程序可以做到这一点吗 命令是什么 第一个是xhtml/xml文件: <html xmlns="http://www.w3.org/1999/xhtml"> <body> <table border="1"> <tr> <td>Day/Time</td> <td>7.30</td> &

我有两个文件

我想用这两个文件创建pdf

  • 有人知道linux上的程序可以做到这一点吗
  • 命令是什么
  • 第一个是xhtml/xml文件:

    <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>
    
    
    天/时间
    7.30
    8.15
    9.05
    9.50
    10.40
    11.25
    12.15
    13
    13.50
    14.35
    15.25
    16.10
    17
    17.45
    18.35
    星期一
    uvin1341.P
    Mult 134 3.P->137
    星期二
    InTe 135 1.P
    马恩336 1.P
    AlSu 134 1.P
    阿尔苏135 1.P
    星期三
    卡丁车134 2.PV
    INTE 041 2.PV
    Aj 139 1.P
    星期四
    盖恩139 2.PV
    SePr 135 1.P
    星期五
    
    第二个是.xsl文件-组合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>
    
    
    
    xsltproc可以应用样式表。ApacheFop可以生成PDF。

    您需要一个XSLT处理器,
    xsltproc
    可能已经在您的Linux发行版中。然后需要一个处理器将FO(格式化对象)转换为PDF。Apache有一个免费的FO处理器(FOP):

    下载并提取FOP后,您的管道可能如下所示:

    $ xsltproc so.xsl so.xml > so.fo
    $ <path-to-extracted-fop-dir>/fop so.fo so.pdf
    
    $xsltproc so.xsl so.xml>so.fo
    $/fop so.fo so.pdf
    
    我对您提供的XML源代码和XSLT做了同样多的尝试,但在运行ApacheFop时出现了错误。我对您的XSLT一无所知,因此您可能可以绕过错误