title: XSLT attribute change based on Value
body: <p>I am new to XSLT and wanted to see if I could have some help.</p>
  
  <p>I currently have an XML that consists on numerous  copy of the format below:</p>
  
  <pre><code>          &lt;item:items&gt;
              &lt;item:item action="ingest" id="USAUS868509"&gt;
                  &lt;item:itemID&gt;1157245&lt;/item:itemID&gt;
                  &lt;item:spotType&gt;commercial&lt;/item:spotType&gt;
              &lt;/item:item&gt;
             &lt;item:items&gt;
  </code></pre>
  
  <p>What I have been tasked with is to replace the value of the id attribute. I need to change this value based on the numerical portion of the code. if the value is greater than 850000 the format should be changed to USA868509. If the value is less than 850000 than you would change the id value to only include the numbers. The rest of the values in the XML should remain exactly the same.</p>
  
  <p>I currently have the xslt below:</p>
  
  <pre><code>             &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:template match="//items/item[@id]"&gt;  
                  &lt;xsl:choose&gt;
                      &lt;xsl:when test="substring(id,5) &amp;gt;= 845986"&gt;
                          &lt;xsl:attribute name="id"&gt;
                              &lt;xsl:value-of select="substring(id,5)"/&gt;
                          &lt;/xsl:attribute&gt; 
                      &lt;/xsl:when&gt;
                      &lt;xsl:otherwise&gt;
                          &lt;xsl:attribute name="id"&gt;
                              &lt;xsl:value-of select="id"/&gt;
                          &lt;/xsl:attribute&gt; 
                      &lt;/xsl:otherwise&gt;
                  &lt;/xsl:choose&gt;
              &lt;/xsl:template&gt;  
  </code></pre>
  
  <p>I am having trouble identifying the value I would like to change because XSLT does not do looping for variables. Is there a way I can change my XSLT to have this logic?</p>