Apply transforms to XML attribute containing escaped HTML

后端 未结 2 392
春和景丽
春和景丽 2021-01-27 16:07

I have some XML that looks like this:



    

        
2条回答
  •  隐瞒了意图╮
    2021-01-27 16:46

    Here's one way you could do it, by calling into a PHP function from XSLT:

    function parseHTMLString($html)
    {
        $doc = new DOMDocument();
        $doc->loadHTML($html);
        return $doc;
    }
    
    $xml = <<
        
            
        
    
    EOB;
    
    $xsl = <<
    
     
       
     
    
     
       

    EOB; $xmldoc = new DOMDocument(); $xmldoc->loadXML($xml); $xsldoc = new DOMDocument(); $xsldoc->loadXML($xsl); $proc = new XSLTProcessor(); $proc->registerPHPFunctions('parseHTMLString'); $proc->importStyleSheet($xsldoc); echo $proc->transformToXML($xmldoc);

提交回复
热议问题