Re: Parsing XML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ashley Sheridan wrote:

>> Roughly like this:  (this is from a project I'm currently working
>> on).
>> 
>> --------------
>> // create the xslt processor object
>> if ( FALSE===($xp=new XSLTProcessor()) ) { print "unable to create
>> xslt engine"; return FALSE; }
>> 
>> // Load the XML source
>> $xml=new DOMDocument;
>> $xml->loadXML($list);
>> 
>> // then load the XSL stylesheet
>> $xsl=new DOMDocument;
>> $xsl->load('getfilebypos.xsl');
>> 
>> // attach the stylesheet
>> $xp->importStyleSheet($xsl);
>> 
>> $pos=$_GET['pos'];
>> $xp->setParameter('', array('pos' => $_GET['pos']) );
>> 
>> $file=$xp->transformToXML($xml);
>> ------------
>> 
>> $file in this case is just a single filename, no XML.  My input data
>> has a list of filenames, the 'pos' argument from the URI identifies
>> one I need to process.
>> 
>> 
>> /Per Jessen, Zürich
>> 
>> 
> So here you're advocating loading the XML document into PHP to add an
> element, then convert the XML into something else, for PHP to read
> back in (not forgetting my original question said I need PHP to do
> some operations on the XML.) 

No, not at all.  1) no element is added, 2) the document is not
loaded 'into' PHP and 3) PHP 'reads back' output of about 30 bytes (a
filename + path). 
None of the XSL+XML happens inside of PHP - it's done through the XSL
extension which is essentially all calls to libxslt. 

> Do you see why I just wanted a way to extract the parts of the XML
> document I needed? This example is actually making something
> unnecessarily complex just because XSL is deemed to be the best way to
> work with XML. 

Ash, my example above extracts a single element (specified by 'pos')
from an XML-document - it's all done by a standards-compliant XSLT
style-sheet, and very effectively so.  The 8 lines of PHP code to
invoke the XSL conversion are virtually 'standard' too.  I'm having a
hard time appreciating why that is better done by combining
somebodyelses custom code with your own custom code.

> I'm not saying that XSL is a bad thing, I've used it many times before
> to convert various document formats, I just think that for what I
> needed, XSL doesn't really suit the task at hand.

I understand what you're saying, I just haven't heard a good argument
yet.

Gotta go watch Dr. House on the telly now.  I'll be back tomorow
morning.


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux