php - 为什么 XSLT 转换输出有尾随数字?
问题描述
我正在将我的 XML 转换为另一个 XML 文件并应用 XSLT 转换,但是转换的输出始终具有尾随数字 1。
这是我的代码
/**
** Input XML
*/
$xml = new \DOMDocument;
$xml->load($file1);
/**
** XSLT File
**/
$xsl = new \DOMDocument;
$xsl->loadXML($file2);
/**
** Combine and Transform XML and XSLT
**/
$proc = new \XSLTProcessor;
$proc->importStyleSheet($xsl);
$transformedOutPut = $proc->transformToXML($xml);
return print_r($transformedOutPut);
这是我的 XML 输入,
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
我有一个这样的 XSLT 文件,
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<catalognew>
<container-title>My Data</container-title>
<xsl:for-each select="catalog/cd">
<cdnew>
<titlenew><xsl:value-of select="title"/></titlenew>
<artistnew><xsl:value-of select="artist"/></artistnew>
</cdnew>
</xsl:for-each>
</catalognew>
</xsl:template>
</xsl:stylesheet>
这是输出结果
<?xml version="1.0"?>
<catalognew>
<container-title>My Data</container-title>
<cdnew>
<titlenew>Empire Burlesque</titlenew>
<artistnew>Bob Dylan</artistnew>
</cdnew>
</catalognew>
1
我想知道为什么输出上方有一个额外的换行符,文件末尾有一个尾随数字 1,
我希望有人可以帮助我这是我第一次使用此功能。
解决方案
推荐阅读
- typescript - 我可以减少我的 redux 代码中的打字稿样板重复吗?
- javascript - NodeJS 应用程序在多次请求后崩溃
- laravel - 有什么方法可以显示来自 api 的数据吗?
- c - 尝试读取文件时出现分段错误
- c# - 激活另一个单选按钮时清除一个单选按钮的组合框
- ruby-on-rails - 在查询中包含来自另一个表的列(rails activerecord)
- angular - 部署角度和弹簧启动应用程序的问题
- assembly - 理解 x86-64 调用操作数
- c# - 根据 WPF XAML 中的 IsChecked 属性更改 CheckBox 样式
- android - 重复构建失败“要使用协程功能,您必须添加`ktx`.......”