XML : Recursive loop, multiple conditions in XSL

I have an XML document with multiple instances and types of children within an element type, and need to display them both in order and with different formatting for each child type.

I've tried different combinations of for-each and conditional choose loops, but with no luck.

XML Segment:

  <PERSONAE>  <TITLE>Dramatis Personae</TITLE>    <PERSONA>CLAUDIUS, king of Denmark. </PERSONA>  <PERSONA>HAMLET, son to the late, and nephew to the present king.</PERSONA>  <PERSONA>POLONIUS, lord chamberlain. </PERSONA>  <PERSONA>HORATIO, friend to Hamlet.</PERSONA>  <PERSONA>LAERTES, son to Polonius.</PERSONA>  <PERSONA>LUCIANUS, nephew to the king.</PERSONA>    <PGROUP>  <PERSONA>VOLTIMAND</PERSONA>  <PERSONA>CORNELIUS</PERSONA>  <PERSONA>ROSENCRANTZ</PERSONA>  <PERSONA>GUILDENSTERN</PERSONA>  <PERSONA>OSRIC</PERSONA>  <GRPDESCR>courtiers.</GRPDESCR>  </PGROUP>    <PERSONA>A Gentleman</PERSONA>  <PERSONA>A Priest. </PERSONA>    <PGROUP>  <PERSONA>MARCELLUS</PERSONA>  <PERSONA>BERNARDO</PERSONA>  <GRPDESCR>officers.</GRPDESCR>  </PGROUP>    

XSL:

  <h2><xsl:value-of select="PLAY/PERSONAE/TITLE" /></h2>  <xsl:for-each select="PLAY/PERSONAE/node()">      <xsl:choose>          <xsl:when test="PERSONA">              <xsl:value-of select="PERSONA" />          </xsl:when>          <xsl:when test="PGROUP">              <xsl:for-each select="PERSONA">                  <xsl:value-of select="PERSONA" />              </xsl:for-each>              <xsl:value-of select="PGROUP" />          </xsl:when>          <xsl:otherwise />      </xsl:choose>  </xsl:for-each>     

Every time, it either returns only the very first PERSONA child it parses, or it returns the first two PGROUP/PERSONA children. Can anyone see what I'm doing wrong?

No comments:

Post a Comment