在NetBeans中使用PHP脚本将XML/XSL转换为HTML文件


Converting XML/XSL to HTML file using PHP script in NetBeans

我正在尝试用XSL样式表将XML数据转换为HTML输出,我使用一个简单的PHP脚本来完成它,尽管我在制作实际的HTML输出时遇到了麻烦,我想通过Ubuntu终端运行脚本,然后生成HTML文件。

通过导航到脚本所在的位置,我试着运行这个命令,但它只生成一个空白的HTML文件

XMLtoHTML.php -> test.html

脚本:

<?php
// Load the XML source
$xml = new DOMDocument;
$xml->load('test.xml');
$xsl = new DOMDocument;
$xsl->load('test.xsl');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
echo $proc->transformToXML($xml);

EDIT:我刚刚意识到问题可能只是由于使用->而不是>进行输出重定向。

下面的答案仍然有效,只需输入:

XMLtoHTML.php > xsellco.html

如果你还想知道,你的PHP转换器是很好的。
空白输出可能是由于XSL/XML文件中的某些内容。

下面是与您编写的PHP翻译器一起工作的示例文件:

test.xml

<?xml version="1.0"?>
<Hello>, world</Hello>

test.xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="Hello">
<html>
    <body>
        <xsl:value-of select="local-name()"/><xsl:value-of select="."/>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>