title: XSLT Add nested element to the last node based on the existing element
body: <p>I have the following XML, the XML has multiple occurance of 'item' elements, and there will be single occurance of 'info' element</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  
  &lt;root xmlns="http://temo.com/tempe.xsd"&gt;
  
  
  &lt;di&gt;    
  &lt;md&gt;2013-07-09T09:43:00&lt;/md&gt;
  &lt;/di&gt;
  
  
  &lt;list&gt;
  
  &lt;item&gt;
  &lt;Name&gt;test&lt;/Name&gt;
  &lt;section block1="true"&gt;
  &lt;block1&gt;
  &lt;move&gt;1&lt;/move&gt;
  &lt;info&gt;
  &lt;item1&gt;test item 1&lt;/item1&gt;
  &lt;item2&gt;false&lt;/item2&gt;
  &lt;item3&gt;1&lt;/item3&gt;
  &lt;/info&gt;
  &lt;/block1&gt;
  &lt;block2&gt;
  ...
  &lt;/block2&gt;
  &lt;/section&gt;
  &lt;/item&gt;
  &lt;/list&gt;
  
  &lt;option&gt;
  ...
  &lt;/option&gt;
  
  &lt;/root&gt;
  </code></pre>
  
  <p>and I want to convert it to the below format, i.e.,  if 'move' element is present then add new elements in the last position of 'info' element should be created</p>
  
  <pre><code>&lt;item4&gt;
   &lt;item5&gt;1&lt;/item5&gt;
  &lt;/item4&gt;
  
  
  &lt;?xml version="1.0" encoding="utf-8" ?&gt;
  
  &lt;root xmlns="http://temo.com/tempe.xsd"&gt;
  
  
  &lt;di&gt;    
  &lt;md&gt;2013-07-09T09:43:00&lt;/md&gt;
  &lt;/di&gt;
  
  
  &lt;list&gt;
  
  &lt;item&gt;
  &lt;Name&gt;test&lt;/Name&gt;
  &lt;section block1="true"&gt;
  &lt;block1&gt;
  &lt;move&gt;1&lt;/move&gt;
  &lt;info&gt;
    &lt;item1&gt;test item 1&lt;/item1&gt;
    &lt;item2&gt;false&lt;/item2&gt;
    &lt;item3&gt;1&lt;/item3&gt;
    &lt;item4&gt;
      &lt;item5&gt;1&lt;/item5&gt;
    &lt;/item4&gt;
  &lt;/info&gt;
  &lt;/block1&gt;
    &lt;block2&gt;
      ...
    &lt;/block2&gt;
  &lt;/section&gt;
  &lt;/item&gt;
  &lt;item&gt;
      ...
  &lt;/item&gt;
  &lt;/list&gt;
  &lt;option&gt;
  ...
  &lt;/option&gt;
  
  &lt;/root&gt;
  </code></pre>
  
  <p>I am using the following XSLT to convert to the above format</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
  &gt;
  &lt;xsl:output method="xml" indent="yes" encoding="utf-8"/&gt;
  
  &lt;xsl:template match="node()|@*" name="identity"&gt;
  &lt;xsl:copy&gt;
  &lt;xsl:apply-templates select="node()|@*"/&gt;
  &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="/info/*[position()=last()]"&gt;
  &lt;xsl:copy&gt;
  &lt;xsl:choose&gt;
  &lt;xsl:when test="/section/block/move"&gt;
  &lt;!--Add new element item4--&gt;
  &lt;xsl:element name="item4"&gt;
  &lt;xsl:element name="item5"&gt;
  &lt;xsl:value-of select="section/block/move"/&gt;
  &lt;/xsl:element&gt;
  &lt;/xsl:element&gt;
  &lt;/xsl:when&gt;
  &lt;xsl:otherwise&gt;
  &lt;xsl:call-template name="identity" /&gt;
  &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Could you please Help me to find the issue in the XSLT?
  I am new to XSLT</p>
  
  <p>Thank you :)</p>