Re: Parsing XML

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

 



On Mon, 2008-12-01 at 21:35 +0100, Per Jessen wrote:
> Ashley Sheridan wrote:
> 
> > I still disagree, as using XSL is essentially converting the XML to
> > another format, 
> 
> Which is all you're doing when you're extracting parts of an XML
> document.  
> 
> > which is then being used by PHP. XSL is great for some tasks, but for
> > this, I think having a good PHP XMLDoc (or similar type of) class is
> > better. 
> 
> Ash, I'd really like to hear you argue why you think so.
> 
> I can't help thinking it's a bit like saying "I know there is a compiler
> for C-code, but I prefer to convert to assembler by using PHP".  I know
> it's not quite that bad, but I hope you get my point.
> 
> > On a slightly aside note though, how would you apply the XSL to the
> > XML using PHP? 
> 
> 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.) 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.

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.


Ash
www.ashleysheridan.co.uk


-- 
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