title: XSL - Previous node value in the loop
body: <p>I have an XML like this - (simplified)</p>
  
  <pre><code>&lt;OrderBundle&gt;
      &lt;BundleDetail&gt;
          &lt;BundleId&gt;12312&lt;/BundleId&gt;
          &lt;BundleUnit&gt;
              &lt;Idset&gt;
                  &lt;PartNo&gt;807651&lt;/PartNo&gt;
              &lt;/Idset&gt;
          &lt;/BundleUnit&gt;
      &lt;/BundleDetail&gt;
      &lt;BundleDetail&gt;
          &lt;BundleId&gt;12112&lt;/BundleId&gt;
          &lt;BundleUnit&gt;
              &lt;Idset&gt;
                  &lt;PartNo&gt;807650&lt;/PartNo&gt;
              &lt;/Idset&gt;
          &lt;/BundleUnit&gt;
      &lt;/BundleDetail&gt;
      &lt;BundleDetail&gt;
          &lt;BundleId&gt;12412&lt;/BundleId&gt;
          &lt;BundleUnit&gt;
              &lt;Idset&gt;
                  &lt;PartNo&gt;807651&lt;/PartNo&gt;
              &lt;/Idset&gt;
          &lt;/BundleUnit&gt;
      &lt;/BundleDetail&gt;
      &lt;BundleDetail&gt;
          &lt;BundleId&gt;12612&lt;/BundleId&gt;
          &lt;BundleUnit&gt;
              &lt;Idset&gt;
                  &lt;PartNo&gt;807651&lt;/PartNo&gt;
              &lt;/Idset&gt;
          &lt;/BundleUnit&gt;
      &lt;/BundleDetail&gt;
  &lt;/OrderBundle&gt;
  </code></pre>
  
  <p>I am using this XSL to find the previous value of similar node in the loop. I simiplified the xsl here, i need to fit this logic in a bigger set.. </p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
  
  &lt;xsl:template match="/"&gt;
  
    &lt;html&gt;
    &lt;body&gt;
  
      &lt;table border="1"&gt;
          &lt;tr&gt;
              &lt;th&gt;Bundle Id&lt;/th&gt;
              &lt;th&gt;PartNo&lt;/th&gt;
              &lt;th&gt;PreviousValue&lt;/th&gt;
          &lt;/tr&gt;
        &lt;xsl:for-each select="/OrderBundle/BundleDetail"&gt;
        &lt;tr&gt;
          &lt;td&gt; &lt;xsl:value-of select="BundleId"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;xsl:value-of select=" BundleUnit/Idset/PartNo" /&gt; &lt;/td&gt;
          &lt;td&gt; ?? &lt;xsl:value-of select="ancestor::BundleUnit/Idset/PartNo"/&gt;   &lt;/td&gt;
        &lt;/tr&gt;
        &lt;/xsl:for-each&gt;
      &lt;/table&gt;
  
  
    &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>I tried with ancestor and previous-sibling, doesnt work for me.. 
  I am expecting below result</p>
  
  <pre><code>B.Id  PartNo PreviousValue 
  12312 807651 ??             --
  12112 807650 ??             -- 807651 
  12412 807651 ??             -- 807650 etc
  12612 807651 ??  
  </code></pre>
  
  <p>any ideas please ?</p>