title: XSL For-Each Looping
body: <p>Basically this is my XML taken from an excerpt of a Shakespeare play: </p>
  
  <pre><code>&lt;PLAY&gt;
  &lt;PERSONA&gt;BENEDICK, a young lord of Padua.&lt;/PERSONA&gt;
  &lt;PERSONA&gt;LEONATO, governor of Messina.&lt;/PERSONA&gt;
  &lt;PERSONA&gt;ANTONIO, his brother.&lt;/PERSONA&gt;
  &lt;PERSONA&gt;BALTHASAR, attendant on Don Pedro.&lt;/PERSONA&gt;
  &lt;PGROUP&gt;
      &lt;PERSONA&gt;CONRADE&lt;/PERSONA&gt;
      &lt;PERSONA&gt;BORACHIO&lt;/PERSONA&gt;
      &lt;GRPDESCR&gt;followers of Don John.&lt;/GRPDESCR&gt;
  &lt;/PGROUP&gt;
  &lt;PERSONA&gt;FRIAR FRANCIS&lt;/PERSONA&gt;
  &lt;/PLAY&gt;
  </code></pre>
  
  <p>Here's the XSL:</p>
  
  <pre><code>&lt;xsl:template match="PLAY"&gt;
      &lt;html&gt;
      &lt;body&gt;
           &lt;xsl:for-each select="PERSONAE"&gt;
  
                &lt;xsl:apply-templates select="PERSONA" /&gt;
                &lt;xsl:apply-templates select="PGROUP/PERSONA" /&gt;
  
            &lt;/xsl:for-each&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="PERSONA"&gt;
      &lt;p&gt;&lt;xsl:value-of select="." /&gt;&lt;/p&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="PGROUP/PERSONA"&gt;
      &lt;xsl:for-each select="."&gt;
          &lt;p&gt;&lt;xsl:value-of select="." /&gt;, &lt;/p&gt; 
      &lt;/xsl:for-each&gt;
  
      &lt;xsl:for-each select=".."&gt;
          &lt;p&gt;&lt;xsl:value-of select="GRPDESCR" /&gt;&lt;/p&gt;
      &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>The current HTML output:</p>
  
  <pre><code>BENEDICK, a young lord of Padua.
  
  LEONATO, governor of Messina.
  
  ANTONIO, his brother.
  
  BALTHASAR, attendant on Don Pedro.
  
  FRIAR FRANCIS
  
  CONRADE,
  
  followers of Don John.
  
  BORACHIO,
  
  followers of Don John.
  </code></pre>
  
  <p>And this is what I want my HTML output to look like:</p>
  
  <pre><code>BENEDICK, a young lord of Padua.
  
  LEONATO, governor of Messina.
  
  ANTONIO, his brother.
  
  BALTHASAR, attendant on Don Pedro.
  
  FRIAR FRANCIS
  
  CONRADE, BORACHIO, followers of Don John.
  </code></pre>
  
  <p>I've spent hours on this so any help would be so great!</p>