title: XSLT escaping characters for XML attributes
body: <p>I am working in a framework (cocoon) which means that the pages after I produce them are re-transformed by processes I have little or no control of.  What I am doing is making a web service call, then transforming the results into an HTML page for presentation.  Sounds like a job for XSLT.  Everything works fine, until the data returned in an XML text node has an '&amp;' character in it.  The returned XML is properly escaped, but I want to put it into the href attribute of an anchor  node.  Everything I have tried ends up with the unescaped '&amp;' character showing up in the href attribute.  For example:</p>
  
  <p>If the node returned from the web service looks like:</p>
  
  <pre><code>&lt;ns:name&gt;Foo&amp;amp;Bar&lt;/ns:name&gt;
  </code></pre>
  
  <p>The resulting <code>&lt;a&gt;</code> token (in the page source) looks like:</p>
  
  <pre><code>&lt;a href="ADifferentPage.jsp?name=Foo&amp;Bar"&gt;Foo&amp;amp;Bar&lt;/a&gt;
  </code></pre>
  
  <p>My current XSLT code looks like:</p>
  
  <pre><code>&lt;a&gt;
    &lt;xsl:attribute name="href"&gt;
      ADifferentPage.jsp?name=&lt;xsl:value-of select="ns:name" /&gt;
    &lt;/xsl:attribute&gt;
    &lt;xsl:value-of select="ns:name" /&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>The desired result is:</p>
  
  <pre><code>&lt;a href="ADifferentPage.jsp?name=Foo&amp;amp;Bar"&gt;Foo&amp;amp;Bar&lt;/a&gt;
  </code></pre>