title: Change value of a xml field based on condition using xslt
body: <p>I need to change value of a field in xml based on some condition using xslt.</p>
  
  <p>My input xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rows&gt;
      &lt;item&gt;
          &lt;Name&gt;ABC&lt;/Name&gt;
          &lt;ID&gt;1234&lt;/ID&gt;
      &lt;/item&gt;
      &lt;item&gt;
          &lt;Name&gt;XYX&lt;/Name&gt;
          &lt;ID&gt;234&lt;/ID&gt;
      &lt;/item&gt;
      &lt;item&gt;
          &lt;Name&gt;PXC&lt;/Name&gt;
          &lt;ID&gt;456&lt;/ID&gt;
      &lt;/item&gt; 
  &lt;/rows&gt;
  </code></pre>
  
  <p>My XSL code:</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:template match="@*|node()"&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="@*|node()"/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:variable name="ID" select="/rows/item/ID"/&gt;
      &lt;xsl:template match="/rows/item/ID"&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="$ID = '1234'"&gt;1001&lt;/xsl:when&gt;
              &lt;xsl:when test="$ID = '234'"&gt;1002&lt;/xsl:when&gt;
              &lt;xsl:when test="$ID = '456'"&gt;1003&lt;/xsl:when&gt;
              &lt;xsl:when test="$ID = '789'"&gt;1004&lt;/xsl:when&gt;
              &lt;xsl:when test="$ID = '1903'"&gt;1005&lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:message terminate="no"&gt;SEVERE: No ID Mapping is found &lt;xsl:value-of select="$ID"/&gt;
                  &lt;/xsl:message&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Output xml:</p>
  
  <pre><code>&lt;rows&gt;
      &lt;item&gt;
          &lt;Name&gt;ABC&lt;/Name&gt;
          1001
      &lt;/item&gt;
      &lt;item&gt;
          &lt;Name&gt;XYX&lt;/Name&gt;
          1001
      &lt;/item&gt;
      &lt;item&gt;
          &lt;Name&gt;PXC&lt;/Name&gt;
          1001
      &lt;/item&gt; 
  &lt;/rows&gt;
  </code></pre>
  
  <p>i am expecting the value of ID field to change based on my choose condition. And if a value that is not maintained in the choose condition comes then it should throw error.</p>
  
  <p>But the output xml is missing the xml tag for ID field and also the first choose condition value is applied to below items. Kindly help me in correcting the code.</p>