<p>I have an XML definition that contains an element with child elements. For example:</p>

<pre><code>&lt;a&gt;
 &lt;b&gt;
  &lt;c&gt;C&lt;/c&gt;
  &lt;d&gt;D&lt;/d&gt;
 &lt;/b&gt;
&lt;/a&gt;
</code></pre>

<p>I have an XSLT with an output of text. For example:</p>

<pre><code>&lt;xsl...&gt;
  &lt;xsl:output method="text" indent="yes"/&gt;
  &lt;xsl:template match="/"&gt;
    &lt;xsl:copy-of select="/a/b" /&gt;
  ...
</code></pre>

<p>I want to copy the entire b element and its children into a whitespace-removed string so that I can generate a SQL query. For example:</p>

<pre><code>select * from some-table where xml = '&lt;b&gt;&lt;c&gt;C&lt;/c&gt;&lt;d&gt;D&lt;/d&gt;&lt;/b&gt;'
</code></pre>

<p>At the moment copy-of is finding the b element but dropping off all element and attribute information leaving only the text content within each. I think this might be to do with the output type.</p>

<p>Any ideas?</p>

Your SQL statement scares me. XML is case-sensitive, and your comparison there is likely to fail if the input XML and XSLT (including all elements, attributes, and values) aren't cased exactly like that used in the original database insert.
I believe both Oracle (certain) and SQL Server (think so) have mechanisms to do a query against a column containing XML in a more XML-friendly way (for instance, using XPath).
What exactly are you trying to do? Your problem seems deeper than just getting this XSLT to transform correctly.