title: Swap items in a sequence
body: <p>I am trying to write a heap sort algorithm using XSLT .But struggling to swap the values of the variable used for storing the tokenized values. I have created method heapify for comparing the values and swap the larger value to the current index. Anyone please help direct me to swap the values of the parent list.</p>
  
  <pre><code>&lt;xsl:template match="/"&gt;
  
        &lt;xsl:variable name="tokenizedSample" select="tokenize(.,' ')"&gt;             
      &lt;/xsl:variable&gt;
      &lt;!--&lt;xsl:value-of select="."/&gt;--&gt;
      &lt;xsl:call-template name="BuildHeap"&gt;
        &lt;xsl:with-param name="intList" select="$tokenizedSample"/&gt;
      &lt;/xsl:call-template&gt;
    &lt;/xsl:template&gt;
  
  
  
    &lt;xsl:template name="BuildHeap"&gt;
     &lt;xsl:param name="intList"/&gt;
        &lt;xsl:for-each select="$intList"&gt;
          &lt;xsl:call-template name="Heapify"&gt;
            &lt;xsl:with-param name="newintList" select="$intList"/&gt;
            &lt;xsl:with-param name="index"  select="position()"/&gt;
          &lt;/xsl:call-template&gt;
        &lt;/xsl:for-each&gt;
   &lt;/xsl:template&gt;
  
  
  
    &lt;xsl:template name="Heapify"&gt;    
      &lt;xsl:param name="newintList"/&gt;
      &lt;xsl:param name="index"/&gt;
      &lt;xsl:variable name="stringval"&gt;
        &lt;xsl:text&gt;&lt;/xsl:text&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:variable name="vIndex"&gt;
        &lt;xsl:number value="$index" /&gt;
      &lt;/xsl:variable&gt;
  
      &lt;xsl:variable name="stringval" select="concat(($stringval),'is')"/&gt;
      &lt;xsl:if test="$newintList[$vIndex*2] &amp;gt; $newintList[$vIndex*1]  and $newintList[$vIndex*2] &amp;gt; $newintList[($vIndex*2)+1] "&gt;
  
      &lt;!—swap the values of ith position with 2ith position--&gt;
  
        &lt;xsl:for-each select="$newintList"&gt;
          &lt;xsl:if test="position()=$vIndex"&gt;
            &lt;xsl:value-of select="$newintList[$vIndex*2]"/&gt;
            &lt;xsl:value-of select="$stringval"/&gt;
            &lt;xsl:variable name="stringval" select="concat(($stringval),'is',$newintList[$vIndex*2])"/&gt;
            &lt;xsl:value-of select="$stringval"/&gt;
          &lt;/xsl:if&gt;
  
          &lt;xsl:if test="position()=($vIndex*2)"&gt;
            &lt;xsl:value-of select="$stringval"/&gt;
            &lt;xsl:variable name="stringval" select="concat(($stringval),'is')"/&gt;
            &lt;xsl:value-of select="$stringval"/&gt;
            &lt;xsl:variable name="stringval" select="concat(($stringval),'is',$newintList[$vIndex*1])"/&gt;
          &lt;/xsl:if&gt;
  
        &lt;/xsl:for-each&gt;
  
  &lt;xsl:value-of select="$stringval"/&gt;
      &lt;/xsl:if&gt;
  
  
      &lt;xsl:if test="$newintList[($vIndex*2)+1] &amp;gt; $newintList[$vIndex*1]  and $newintList[($vIndex*2)+1] &amp;gt; $newintList[$vIndex*2] "&gt;
      &lt;!—swap the values of ith position with 2i+1th position--&gt;
  
      &lt;/xsl:if&gt;
  
    &lt;/xsl:template&gt;
  </code></pre>