Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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
Php 对xpath选择返回的SimpleXML元素使用TransformToXml_Php_Xslt_Simplexml - Fatal编程技术网

Php 对xpath选择返回的SimpleXML元素使用TransformToXml

Php 对xpath选择返回的SimpleXML元素使用TransformToXml,php,xslt,simplexml,Php,Xslt,Simplexml,我希望能够使用XSLT处理XPath选择的XML片段。当我传递$xmlsippet时,它的行为就像我传递了整个$xml一样。我如何告诉处理器处理代码段而不是整个文件 XML 没有得到任何答案,我只是通过构建一个字符串并将其加载为XML来解决这个问题 $cfString = ''; foreach( $cfArray as $item){ $cfString .= $item->asXML(); } $cfXml = <<<XML <?xml version

我希望能够使用XSLT处理XPath选择的XML片段。当我传递
$xmlsippet
时,它的行为就像我传递了整个
$xml
一样。我如何告诉处理器处理代码段而不是整个文件

XML


没有得到任何答案,我只是通过构建一个字符串并将其加载为XML来解决这个问题

$cfString = '';
foreach( $cfArray as $item){
    $cfString .= $item->asXML();
}

$cfXml = <<<XML
<?xml version='1.0'?> 
<FMPReport>
<File name="{$fileName[0]}">
<CustomFunctionCatalog>
$cfString
</CustomFunctionCatalog>
</File>
</FMPReport>
XML;

$xml  = simplexml_load_string($cfXml);
$cfString='';
foreach($cfArray作为$item){
$cfString.=$item->asXML();
}
$cfXml=
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" encoding="UTF-8"/>
    <xsl:template match="/">
        <xsl:value-of select="name(child::*[1])"/>
        </xsl:template>
    <xsl:template match="text()" />
</xsl:stylesheet>
function displayCustomFunction($customFunctionId) {
    LIBXML_NOWARNING;
    LIBXML_NOCDATA;
    LIBXML_PARSEHUGE;
    LIBXML_BIGLINES;
    LIBXML_COMPACT;
    $filePath = 'xml/abc';
    $xslPath = 'xsl/abc';
    $xml = simplexml_load_file( $filePath, 'SimpleXMLElement');
    // ->xpath returns an array, in this case, an array of one item. array()[0] will be a SimpleXMLElement
    $xmlSnippet  = $xml->xpath('File/CustomFunctionCatalog/CustomFunction[@id=\''.$customFunctionId.'\']')[0];
    $xsl = simplexml_load_file( $xslPath, 'SimpleXMLElement');
    $xslt = new XSLTProcessor();
    $xslt->importStylesheet($xsl);
    $xslt->transformToXml($xml);        // returns 'FMPReport'
    $xslt->transformToXml($xmlSnippet); // returns 'FMPReport'. Expecting 'Calculation'
}
$cfString = '';
foreach( $cfArray as $item){
    $cfString .= $item->asXML();
}

$cfXml = <<<XML
<?xml version='1.0'?> 
<FMPReport>
<File name="{$fileName[0]}">
<CustomFunctionCatalog>
$cfString
</CustomFunctionCatalog>
</File>
</FMPReport>
XML;

$xml  = simplexml_load_string($cfXml);