title: XSLT for-each loop iterating through 2 elements with same name but different attribute
body: <p>Note: Solution should be in XSLt 1.0</p>
  
  <p>I'm a complete novice with XSLT so apologies if solutions to other questions relating to loops would work for my problem but I've had no luck so far.</p>
  
  <p>I have an XML file with multiple nodes such as the following:</p>
  
  <pre><code>&lt;Roles&gt;
    &lt;field name="linecode" instance="1" value="EY"/&gt;
    &lt;field name="number" instance="1" value="265"/&gt;
    &lt;field name="linecode" instance="2" value="PK"/&gt;
    &lt;field name="number" instance="2" value="123"/&gt;
    &lt;field name="abc" instance="1" value="123"/&gt;
    &lt;field name="xyz" instance="1" value="123"/&gt;
  &lt;/Role&gt;
  </code></pre>
  
  <p>I need to loop through these nodes and print <code>&lt;field name="linecode"&gt;</code> along with its matching instance no <code>&lt;field name="number"&gt;</code>. However, if I use a for-each loop it will iterate through the <code>&lt;field name="linecode"&gt;s</code> fine but print the same <code>&lt;field name="number"&gt;</code> is not working.</p>
  
  <p>Is there any way I can sync them up so that, for example the output will be </p>
  
  <pre><code>EY - 265
  PK - 123
  </code></pre>
  
  <p>I have also tried to use the <code>following-sibling</code> but its not working for me.. Any help is highly appreciated. .</p>
  
  <p>Here's my sample xslt. </p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
  &lt;xsl:template match="Roles"&gt;
      &lt;xsl:for-each select="field[@name='linecode']"&gt;
          &lt;xsl:value-of select="@value"/&gt;
          &lt;xsl:text&gt; - &lt;/xsl:text&gt;
          &lt;xsl:value-of select="field[@name='number' and instance='@instance']"/&gt;
          &lt;xsl:text&gt;&amp;#xa;&lt;/xsl:text&gt;
      &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p></p>
  
  <p>If anyone could think an alternative to loops which would work as well I would appreciate it.</p>