title: using xslt to rename node to node's name concatenated with its index
body: <p>I use the below xslt to transform xmls, it iterates thru the Receipt/Process
  nodes and adds type attributes to the nodes. Based on the node's value it will be string/int/float.
  That part works fine.</p>
  
  <p>I also should rename the "Node" node to "Node" concatenated with its index and 
  add an attribute which should be the "Name" node's value. </p>
  
  <p>I may have multiple "Nodes" which I would like to convert to something like this:</p>
  
  <p>first Node  to where the "Cuda3DLut" is coming from the <code>&lt;Name&gt;Cuda3DLut&lt;/Name&gt;</code></p>
  
  <pre><code>&lt;Node1 type="Cuda3DLut" &gt;
  &lt;Input  type="ToolLink" role="Input" format="red,green,blue"&gt;Source&lt;/Input&gt;
  &lt;Lut type="string"&gt;Identity&lt;/Lut&gt;
  &lt;Output type="ToolLink" role="Output" format="red,green,blue"&gt;RESULT1&lt;/Output&gt;
  &lt;bypass type="int"&gt;0&lt;/bypass&gt;
  &lt;nodeRole type="string"&gt;viewing&lt;/nodeRole&gt;
  &lt;nodeShortName type="string"&gt;LUT&lt;/nodeShortName&gt;
  &lt;/Node1&gt;
  </code></pre>
  
  <p>second Node  to </p>
  
  <pre><code>&lt;Node2 type="CudaTool" &gt;
  ...
  &lt;/Node2&gt;
  </code></pre>
  
  <p>I also would like to change the "Input" node's value if it is "MainMedia" to "Source" but only then.</p>
  
  <p>Thanks a lot. </p>
  
  <pre><code>Source XML:
  
  &lt;Receipt&gt;
  
    &lt;Process&gt;
      &lt;Node&gt;
        &lt;Name&gt;Cuda3DLut&lt;/Name&gt;
        &lt;Input&gt;MainMedia&lt;/Input&gt;
        &lt;Lut&gt;Identity&lt;/Lut&gt;
        &lt;Output&gt;RESULT1&lt;/Output&gt;
        &lt;bypass&gt;0&lt;/bypass&gt;
        &lt;nodeRole&gt;viewing&lt;/nodeRole&gt;
        &lt;nodeShortName&gt;LUT&lt;/nodeShortName&gt;
      &lt;/Node&gt;
     &lt;Node&gt;
        &lt;Name&gt;CudaTool&lt;/Name&gt;
        &lt;Input&gt;MainMedia&lt;/Input&gt;
        &lt;Lut&gt;Identity&lt;/Lut&gt;
        &lt;Output&gt;RESULT1&lt;/Output&gt;
        &lt;bypass&gt;0&lt;/bypass&gt;
        &lt;nodeRole&gt;viewing&lt;/nodeRole&gt;
        &lt;nodeShortName&gt;LUT&lt;/nodeShortName&gt;
      &lt;/Node&gt;
    &lt;/Process&gt;
  
    &lt;Encode&gt;
      &lt;Job&gt;
       ...
      &lt;/Job&gt;
    &lt;/Encode&gt;
  
  &lt;/Receipt&gt;
  
  xslt: 
  
  &lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
    &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt;
  
    &lt;xsl:template match="/"&gt;
        &lt;cut&gt;
          &lt;xsl:apply-templates/&gt;        
      &lt;/cut&gt;
   &lt;/xsl:template&gt;
  
  
    &lt;xsl:template match="Process"&gt;
  
        &lt;xsl:for-each select="Node/*"&gt;
  
          &lt;xsl:choose&gt;
  
              &lt;xsl:when test="name() = 'Input'"&gt;
  
                &lt;xsl:copy&gt;
                  &lt;xsl:attribute name="type"&gt;ToolLink&lt;/xsl:attribute&gt;
                  &lt;xsl:attribute name="role"&gt;Input&lt;/xsl:attribute&gt;
                  &lt;xsl:attribute name="format"&gt;red,green,blue&lt;/xsl:attribute&gt;
                  &lt;xsl:apply-templates select="@*|node()" /&gt;
                &lt;/xsl:copy&gt;              
  
              &lt;/xsl:when&gt;
  
              &lt;xsl:when test="name() = 'Output'"&gt;
                &lt;xsl:copy&gt;
                  &lt;xsl:attribute name="type"&gt;ToolLink&lt;/xsl:attribute&gt;
                  &lt;xsl:attribute name="role"&gt;Output&lt;/xsl:attribute&gt;
                  &lt;xsl:attribute name="format"&gt;red,green,blue&lt;/xsl:attribute&gt;
                  &lt;xsl:apply-templates select="@*|node()" /&gt;
                &lt;/xsl:copy&gt;              
  
              &lt;/xsl:when&gt;
  
            &lt;xsl:otherwise&gt;
  
              &lt;!-- Add type attribute to the node based on its value --&gt;
              &lt;xsl:choose&gt;
              &lt;xsl:when test="number(.) = ."&gt;
                &lt;xsl:choose&gt;
                  &lt;xsl:when test="contains(., '.')"&gt;
                  &lt;xsl:copy&gt;
                    &lt;xsl:attribute name="type"&gt;float&lt;/xsl:attribute&gt;
                    &lt;xsl:apply-templates select="@*|node()" /&gt;
                  &lt;/xsl:copy&gt;
                &lt;/xsl:when&gt;
                &lt;xsl:otherwise&gt;
                  &lt;xsl:copy&gt;
                    &lt;xsl:attribute name="type"&gt;int&lt;/xsl:attribute&gt;
                    &lt;xsl:apply-templates select="@*|node()" /&gt;
                  &lt;/xsl:copy&gt;
                &lt;/xsl:otherwise&gt;
               &lt;/xsl:choose&gt;                                      
              &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                &lt;xsl:copy&gt;
                  &lt;xsl:attribute name="type"&gt;string&lt;/xsl:attribute&gt;
                  &lt;xsl:apply-templates select="@*|node()" /&gt;
                &lt;/xsl:copy&gt;            
              &lt;/xsl:otherwise&gt;            
            &lt;/xsl:choose&gt;
  
          &lt;/xsl:otherwise&gt;            
          &lt;/xsl:choose&gt;
  
        &lt;/xsl:for-each&gt;
  
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="Encode"&gt;    
    &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>