Generate TreeView (Structure) from XML using PHP

XSLTProcessor

The XSL extension implements the XSL standard, performing » XSLT transformations using the » libxslt library

Code:


    $xslt = new SimpleXMLElement('<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
       <xsl:template match="*">
           <ul>
                <li><xsl:value-of select="local-name()"/>
                 <xsl:apply-templates/>
                </li>
           </ul>
        </xsl:template>
    </xsl:stylesheet>');
                                
    $xml = new SimpleXMLElement($_POST['xmlcontent']);
    $xsl_processor = new XSLTProcessor();
    $xsl_processor->importStylesheet($xslt);
    echo $xsl_processor->transformToXml($xml);