将XML转换为HTML - 使用PHP和XLS模板

时间:2023-01-15 11:41:18

I have this very simple CODE, which should generate me HTML, but all I get is white page. I tryed nearly anything, it just blank page. If anyone could check and tell me what im doing wrong I would be in heavens!

我有这个非常简单的CODE,它应该生成HTML,但我得到的只是白页。我几乎尝试了任何东西,它只是空白页面。如果有人能检查并告诉我我做错了什么,我会在天堂!

PHP CODE:

PHP代码:

        $xp = new XsltProcessor();
    // create a DOM document and load the XSL stylesheet
    $xsl = new DomDocument;
    $xsl->load('template-file.xls');
    // import the XSL styelsheet into the XSLT process
    $xp->importStylesheet($xsl);
    // create a DOM document and load the XML datat
    $xml_doc = new DomDocument;
    $xml_doc->load('temporary-file.xml');
    // transform the XML into HTML using the XSL file
    if ($html = $xp->transformToXML($xml_doc)) {
        return $html;
    } else {        
        return "<p>FAILED</p>";
    }

XML file:

XML文件:

    <?xml version="1.0"?>
<results>
    <xml_report>
    <subject>
         <efx_file_header>
              <efx_header>
                <bureau>EFX</bureau>
                <customer_number>682ZB08042</customer_number>
                <customer_reference_code>199</customer_reference_code>
                <ecoa>2</ecoa>
                <output_format>02</output_format>

                <multiple_files_indicator>1</multiple_files_indicator>
                <name>ZUVICH, TYLER J</name>
                <ssn>196722017</ssn>

              </efx_header>
         </efx_file_header>
   </subject>
    </xml_report>
</results>

And this is the XLS template file:

这是XLS模板文件:

<?xml version="1.0" encoding="utf-8"?>  
<xsl:stylesheet version="1.0"
xmlns:php="http://php.net/xsl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<!-- Edited by Adrian -->

<xsl:output method="html" encoding="UTF-8" indent="yes"/>  

<xsl:template match="results/xml_report">

<xsl:for-each select="subject">
    <table class="table-paddings" cellspacing="0" cellpadding="0">      
        <tbody>
        <tr>
            <td width="245px">Boreau</td>
            <td width="250px"><xsl:value-of select="efx_file_header/ext_header/bureau" /></td>
        </tr>

        <tr>
            <td>Customer Number</td>
            <td><xsl:value-of select="efx_file_header/ext_header/customer_number" /></td>
        </tr>

        <tr>
            <td>Customer Reference Code</td>
            <td><xsl:value-of select="efx_file_header/ext_header/customer_reference_code" /></td>
        </tr>                           

        </tbody>
    </table>
    <br />
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>

1 个解决方案

#1


1  

Try echo $html instead of return $html

尝试echo $ html而不是返回$ html

#1


1  

Try echo $html instead of return $html

尝试echo $ html而不是返回$ html