title: condition on a loop sequence number in XSLT 1.0
body: <p>Can anyone please help me on the below logic of seqence number for each distinct packnumber.
  input:</p>
  
  <pre><code>&lt;Move-Afile&gt;
    &lt;Afile&gt;
      &lt;Item&gt;
        &lt;PackNumber&gt;1234&lt;/PackNumber&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
        &lt;PackNumber&gt;1234&lt;/PackNumber&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
        &lt;PackNumber&gt;1234&lt;/PackNumber&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
        &lt;PackNumber&gt;126&lt;/PackNumber&gt;&lt;!-- different PackNumber counter start from 1 --&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
        &lt;PackNumber&gt;126&lt;/PackNumber&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
        &lt;PackNumber&gt;135&lt;/PackNumber&gt;&lt;!-- different PackNumber counter start from 1 --&gt;
      &lt;/Item&gt;
       &lt;Item&gt;
        &lt;PackNumber&gt;135&lt;/PackNumber&gt;
      &lt;/Item&gt;
    &lt;/Afile&gt;
  &lt;/Move-Afile&gt;
  </code></pre>
  
  <p><code>&lt;Item&gt;</code> is unbounded element.for each Item PackNumber is present.Here there is a condition like for each unique <code>&lt;PackNumber&gt;</code> the counter should start from 1 and gets incremented like below output.</p>
  
  <p>output:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;A&gt;
    &lt;target&gt;
      &lt;counter&gt;1&lt;/counter&gt;
      &lt;PNumber&gt;1234&lt;/PNumber&gt;
      &lt;counter&gt;2&lt;/counter&gt;
      &lt;PNumber&gt;1234&lt;/PNumber&gt;
      &lt;counter&gt;3&lt;/counter&gt;
      &lt;PNumber&gt;1234&lt;/PNumber&gt;
      &lt;counter&gt;1&lt;/counter&gt;&lt;!-- different PackNumber counter start from 1 --&gt;
      &lt;PNumber&gt;126&lt;/PNumber&gt;
      &lt;counter&gt;2&lt;/counter&gt;
      &lt;PNumber&gt;126&lt;/PNumber&gt;
      &lt;counter&gt;1&lt;/counter&gt;&lt;!-- different PackNumber counter start from 1 --&gt;
      &lt;PNumber&gt;135&lt;/PNumber&gt;
      &lt;counter&gt;2&lt;/counter&gt;
      &lt;PNumber&gt;135&lt;/PNumber&gt;  
    &lt;/target&gt;
  &lt;/A&gt; 
  </code></pre>