将XML转换为HTML-使用PHP和XLS模板
我有一个非常简单的代码,可以生成HTML,但我得到的只是一个白色页面。 我几乎什么都试过了,只是一页空白。如果有人能检查并告诉我我做错了什么,那我就完了 PHP代码:将XML转换为HTML-使用PHP和XLS模板,php,html,xml,xslt,Php,Html,Xml,Xslt,我有一个非常简单的代码,可以生成HTML,但我得到的只是一个白色页面。 我几乎什么都试过了,只是一页空白。如果有人能检查并告诉我我做错了什么,那我就完了 PHP代码: $xp = new XsltProcessor(); // create a DOM document and load the XSL stylesheet $xsl = new DomDocument; $xsl->load('template-file.xls'); //
$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 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>
<?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>
$xp=新的XsltProcessor();
//创建DOM文档并加载XSL样式表
$xsl=新文档;
$xsl->load('template-file.xls');
//将XSL样式表导入XSLT进程
$xp->importStylesheet($xsl);
//创建DOM文档并加载XML数据
$xml_doc=新文档;
$xml_doc->load('temporary-file.xml');
//使用XSL文件将XML转换为HTML
如果($html=$xp->transformToXML($xml\u doc)){
返回$html;
}否则{
返回“失败””;
}
XML文件:
$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 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>
<?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>
EFX
682ZB0842
199
2.
02
1.
朱维奇,泰勒J
196722017
这是XLS模板文件:
$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 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>
<?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>
博罗
客户编号
客户参考代码
尝试echo$html
而不是return$html
是否打开显示错误?错误报告设置为E_ALL?@Hajo我完成了,没有错误:如果所有文件都是在php中找到/加载的,并且它们包含dom处理之前所需的数据,则会被选中?@Hajo是的,ofc,至少10x:s因此我现在没有主意,抱歉:(显示错误已打开?错误报告设置为E_ALL?@Hajo我完成了,没有错误:如果所有文件都是在php中找到/加载的,并且它们包含dom处理之前预期的数据,请检查?@Hajo是的,ofc,至少10x:s我现在没有主意,抱歉:(是的,但是如果他不在任何地方重复结果,他会得到他正在经历的准确行为。哇,这么简单?在ECHO:S上损失了150个小时,我怎么会错过:……非常感谢!!!!是的,但是如果他不在任何地方重复结果,他会得到他正在经历的准确行为。哇,这么简单?在ECHO:S上损失了150个小时,呵呵我可以错过那个:……非常感谢!!!!