Re: [PHP-XML-DEV] multiple xsl docs

[email protected] (Kevin Waterson)
Newsgroups php.xml.dev
Organization Oceania
Message-ID <[email protected]>
This one time, at band camp, Christian Stocker <[email protected]> wrote:


> there's no sense in adding a second one IMHO, just transform your XML
> with the first one and then with the second one
perhaps an example would help, this is what I am doing..

  // create new xsltprocessor
  $proc = new xsltprocessor();
  // create a second xsltprocessor
  $proc2 = new xsltprocessor();
  // create new domDocument, this will be the XML
  $dom = new domDocument;
  // create new domDocument,  the main xsl stylesheet
  $dom2 = new domDocument;
  // dom3 is the second xsl stylesheet
  $dom3 = new domDocument;
  // load the xmlstring
  $dom->loadxml($xmlstring);
  // load domDocument from string, the xsl document is also the theme
  // and is stored in the themes directory
  $dom2->load('./path/to/first.xsl');
  // load the xsl from the extention
  $dom3->load('./path/to/second.xsl');
  // import stylesheet from domDocument
  $proc->importStylesheet($dom2);
  // process the xsl from the extension
  $proc2->importStylesheet($dom3);
  // create domDocument from transformation (returns domDocument)
  $result = $proc->transformToDoc($dom);
  // transform again with the second xsl doc
  $result = $proc2->transformToDoc($dom);
  // change the document encoding to HTML
  // this is required so we dont get bizarre UTF-8 chars popping up
  // when using html entities such as &#160;
  $result->encoding = "HTML";
  // output domDocument xml to string
  print $result->savexml();

Here I create the second dom object and use transformToDoc() to apply
the first, then the second

Kind regards
Kevin
-- 
 ______                              
(_____ \                             
 _____) )  ____   ____   ____   ____ 
|  ____/  / _  ) / _  | / ___) / _  )
| |      ( (/ / ( ( | |( (___ ( (/ / 
|_|       \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.