title: Performing an XSLT transformation on part of an XML document selected with DOMXPath
body: <p>Okay this is driving me nuts. I am trying to make a simple CMS using an XML file and some PHP. I have an XML file like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;sections&gt;
  &lt;section name="about"&gt;
      &lt;maintext&gt;
          &lt;p&gt;Here is some maintext. &lt;/p&gt;
      &lt;/maintext&gt;
  &lt;/section&gt;
  &lt;section name="james"&gt;
      &lt;maintext&gt;
          &lt;p&gt;Zippidy do.&lt;/p&gt;
      &lt;/maintext&gt;
  &lt;/section&gt;
  &lt;/sections&gt;
  </code></pre>
  
  <p>Then is the XSL file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
  &lt;xsl:output method="html" /&gt;
  &lt;xsl:template match="/"&gt;
  &lt;xsl:apply-templates /&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="section"&gt;
  &lt;div class="section"&gt;
      &lt;xsl:apply-templates /&gt;
  &lt;/div&gt;  
  &lt;/xsl:template&gt;
  &lt;xsl:template match="maintext"&gt;
  &lt;xsl:copy-of select="child::node()" /&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>This transformation works fine - I get a couple of simple paragraphs:</p>
  
  <pre><code>&lt;p&gt;Here is some maintext. &lt;/p&gt;      
  &lt;p&gt;Zippidy do.&lt;/p&gt;
  </code></pre>
  
  <p>However, I now have a PHP file which should query the XML, take a specific "section" according to its GET parameter. And then run the transformation on just that part of the XML, echoing the result.</p>
  
  <pre><code>&lt;?php
  
  $sectionName = $_GET["section"];
  $content = new DOMDocument();
  $content-&gt;load("content.xml");
  $transformation = new DOMDocument();
  $transformation-&gt;load("transform-content.xsl");
  $processor = new XSLTProcessor();
  $processor-&gt;importStyleSheet($transformation);
  $xpath = new DOMXPath($content);
  $sectionXML = $xpath-&gt;query("section[@name='".$sectionName."']")-&gt;item(0);
  
  echo $processor-&gt;transformToXML($sectionXML);
  ?&gt;
  </code></pre>
  
  <p>Trouble is that whatever I do the whole XML file is transformed, not just the section I've selected with the query. What am I doing wrong here?!</p>