<p><strong>Situation:</strong></p>

<p>I have a simple <em>XML</em> document that contains image information. I need to transform it into <em>HTML</em>. However, I can't see where the open tag is and when I use the <em>XSL</em> code below, it shows the following error message: </p>

<blockquote>
  <p>"Cannot write an attribute node when no element start tag is open."</p>
</blockquote>

<p><strong>XML content:</strong></p>

<pre><code>&lt;root&gt;
    &lt;HeaderText&gt;
        &lt;HeaderText&gt;Dan Testing&lt;/HeaderText&gt;
    &lt;/HeaderText&gt;
    &lt;Image&gt;
        &lt;img width="100" height="100" alt="FPO lady" src="/uploadedImages/temp_photo_small.jpg"/&gt;
    &lt;/Image&gt;
    &lt;BodyText&gt;
        &lt;p&gt;This is a test of the body text&lt;br  /&gt;&lt;/p&gt;
    &lt;/BodyText&gt;
    &lt;ShowLinkArrow&gt;false&lt;/ShowLinkArrow&gt;
&lt;/root&gt;
</code></pre>

<p><strong>XSL code:</strong></p>

<pre><code>&lt;xsl:stylesheet version="1.0" extension-element-prefixes="msxsl"
    exclude-result-prefixes="msxsl js dl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:js="urn:custom-javascript" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:dl="urn:datalist"&gt;
    &lt;xsl:output method="xml" version="1.0" omit-xml-declaration="yes" indent="yes" encoding="utf-8"/&gt;
    &lt;xsl:template match="/" xml:space="preserve"&gt;
        &lt;img&gt;
            &lt;xsl:attribute name="width"&gt;
                100
            &lt;/xsl:attribute&gt;
            &lt;xsl:attribute name="height"&gt;
                100
            &lt;/xsl:attribute&gt;
            &lt;xsl:attribute name="class"&gt;
                CalloutRightPhoto
            &lt;/xsl:attribute&gt;
            &lt;xsl:attribute name="src"&gt;
                &lt;xsl:copy-of select="/root/Image/node()"/&gt;
            &lt;/xsl:attribute&gt;
        &lt;/img&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>

[{'answer_id': 45909, 'author': 'Danimal', 'author_id': 2757, 'author_profile': 'https://Stackoverflow.com/users/2757', 'pm_score': 2, 'selected': False, 'text': '<p>Never mind -- I\'m an idiot. I just needed <b>\n&lt;xsl:value-of select="/root/Image/node()"/&gt;</b></p>\n'}, {'answer_id': 45912, 'author': 'Cory Foy', 'author_id': 4083, 'author_profile': 'https://Stackoverflow.com/users/4083', 'pm_score': 2, 'selected': False, 'text': '<p>Shouldn\'t that be:</p>\n\n<pre><code>&lt;xsl:value-of select="/root/Image/img/@src"/&gt;\n</code></pre>\n\n<p>? It looks like you are trying to copy the entire Image/img node to the attribute @src</p>\n'}, {'answer_id': 45917, 'author': 'harpo', 'author_id': 4525, 'author_profile': 'https://Stackoverflow.com/users/4525', 'pm_score': 2, 'selected': False, 'text': '<p>In order to add attributes, XSL wants</p>\n\n<pre>\n&lt;xsl:element name="img"&gt;\n     (attributes)\n&lt;/xsl:element&gt;\n</pre>\n\n<p>instead of just</p>\n\n<pre>\n&lt;img&gt;\n     (attributes)\n&lt;/img&gt;\n</pre>\n\n<p>Although, yes, if you\'re just copying the element as-is, you don\'t need any of that.</p>\n'}, {'answer_id': 45955, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 6, 'selected': True, 'text': '<p>Just to clarify the problem here - the error is in the following bit of code:</p>\n\n<pre><code>&lt;xsl:attribute name="src"&gt;\n    &lt;xsl:copy-of select="/root/Image/node()"/&gt;\n&lt;/xsl:attribute&gt;\n</code></pre>\n\n<p>The instruction xsl:copy-of takes a node or node-set and makes a copy of it - outputting a node or node-set. However an attribute cannot contain a node, only a textual value, so xsl:value-of would be a possible solution (as this returns the textual value of a node or nodeset).</p>\n\n<p>A MUCH shorter solution (and perhaps more elegant) would be the following:</p>\n\n<pre><code>&lt;img width="100" height="100" src="{/root/Image/node()}" class="CalloutRightPhoto"/&gt;\n</code></pre>\n\n<p>The use of the {} in the attribute is called an Attribute Value Template, and can contain any XPATH expression.</p>\n\n<p>Note, the same XPath can be used here as you have used in the xsl_copy-of as it knows to take the textual value when used in a Attribute Value Template.</p>\n'}, {'answer_id': 12581814, 'author': 'm_cheung', 'author_id': 582032, 'author_profile': 'https://Stackoverflow.com/users/582032', 'pm_score': 0, 'selected': False, 'text': '<p>The other option to try is a straightforward </p>\n\n<pre><code>&lt;img width="100" height="100" src="/root/Image/image.jpeg" class="CalloutRightPhoto"/&gt;\n</code></pre>\n\n<p>i.e. without {} but instead giving the direct image path</p>\n'}]
['https://Stackoverflow.com/questions/45904', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2757/']