[PHP] xsltprocessor
Hello all, I'm having a real problem with applying an xslt transform to a selected part of an xml document. I load the xml document using simplexml_load_file, and the same with the xsl file. Using the xpath function for simplexml I select a part of the xml document and store it in a different variable. I then apply the xml transform to that variable, however the transform actually applies to the whole xml document, rather than just the selected part in the new variable. I can't figure out why it does this. Does anyone know? The code I'm used is below. $xml = simplexml_load_file ( 'simple_test.xml' ); if ( isset ( $_GET['s'] ) && isset ( $_GET['ss'] ) ) foreach ( $xml->xpath( "//[EMAIL PROTECTED]'".$_GET['s']."']/ [EMAIL PROTECTED]'".$_GET['ss']."']" ) as $subsection) $content = $subsection; $xsl = simplexml_load_file( 'simple_test.xsl' ); $proc = new XsltProcessor(); $proc->importStylesheet($xsl); echo $proc->transformToXML($content); Thanks for any help Allan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] xsltprocessor
Hi, you might start by using some braces to explicitly delineate the if and foreach block? ...personally I'm not sure exactly what your code should be doing. Putting the brackets in doesn't make any difference. That part of the code appears to work perfectly - what it does is scan through the xml document looking for a 'section' tag with the attribute id equal to the get variable 's' and with a 'subsection' tag with attribute id equal to the get variable 'ss'. Doing echo $content->asXML(); right after the if and foreach shows that the $content variable does indeed hold the right content. The problem is then applying the xsl transform to what is in that variable. It appears to transform everything in $xml, rather than just what is in $content. $xml = simplexml_load_file ( 'simple_test.xml' ); if ( isset ( $_GET['s'] ) && isset ( $_GET['ss'] ) ) { foreach ( $xml->xpath( "//[EMAIL PROTECTED]'".$_GET['s']."']/ [EMAIL PROTECTED]'".$_GET['ss']."']" ) as $subsection) { $content = $subsection; } } $xsl = simplexml_load_file( 'simple_test.xsl' ); $proc = new XsltProcessor(); $proc->importStylesheet($xsl); echo $proc->transformToXML($content); Thanks Allan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] xsltprocessor
Hi, The problem is then applying the xsl transform to what is in that variable. It appears to transform everything in $xml, rather than just what is in $content. Managed to solve my own problem... Using: $content = $proc->transformToXML(DomDocument::loadXML($content)); To create an xml dom model that can be operated on by the xslt processor. I still have no idea why it would spit out the whole xml document if its not done like that - but never mind... Thanks Allan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php