[RESOLVED] XML - getting a child to use a for-each loop
I have Hamlet in XML. I'm to write a stylesheet. I'm stuck on the <persona> tag. Any help would be greatly appreciated. The "apply-template" doesn't seem to iterate through the <persona> tag and I can't get the for-each loop to work.
<XML>
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="hamlet.xsl"?>
<PLAY>
<TITLE>The Tragedy of Hamlet, Prince of Denmark</TITLE>
<FM>
<P>Text placed in the public domain by Moby Lexical Tools, 1992.</P>
<P>SGML markup by Jon Bosak, 1992-1994.</P>
<P>XML version by Jon Bosak, 1996-1998.</P>
<P>This work may be freely copied and distributed worldwide.</P>
</FM>
<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>
What I have so far:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head><title><xsl:value-of select="PLAY/TITLE"/></title></head>
<body>
<xsl:apply-templates select="PLAY"/>
</body>
</html>
</xsl:template>
<xsl:template match="PLAY">
<xsl:value-of select="FM" /><br /><br />
<xsl:value-of select="PERSONAE/TITLE" /><br />
<xsl:value-of select="PERSONAE/PERSONA"/>
</xsl:template>
</xsl:stylesheet>
[2061 byte] By [
Shodan] at [2007-12-5 11:47:25]

# 2 Re: [RESOLVED] XML - getting a child to use a for-each loop
That was great!! but I have one small snag...
this is more of the xml file..it's long..your example gives me every <persona> tag..not just the ones in the <personae> tag...how do I compensate for that?
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="hamlet.xsl"?>
<PLAY>
<TITLE>The Tragedy of Hamlet, Prince of Denmark</TITLE>
<FM>
<P>Text placed in the public domain by Moby Lexical Tools, 1992.</P>
<P>SGML markup by Jon Bosak, 1992-1994.</P>
<P>XML version by Jon Bosak, 1996-1998.</P>
<P>This work may be freely copied and distributed worldwide.</P>
</FM>
<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>
<PERSONA>FRANCISCO, a soldier.</PERSONA>
<PERSONA>REYNALDO, servant to Polonius.</PERSONA>
<PERSONA>Players.</PERSONA>
<PERSONA>Two Clowns, grave-diggers.</PERSONA>
<PERSONA>FORTINBRAS, prince of Norway. </PERSONA>
<PERSONA>A Captain.</PERSONA>
<PERSONA>English Ambassadors. </PERSONA>
<PERSONA>GERTRUDE, queen of Denmark, and mother to Hamlet. </PERSONA>
<PERSONA>OPHELIA, daughter to Polonius.</PERSONA>
<PERSONA>Lords, Ladies, Officers, Soldiers, Sailors, Messengers, and other Attendants.</PERSONA>
<PERSONA>Ghost of Hamlet's Father. </PERSONA>
</PERSONAE>
<SCNDESCR>SCENE Denmark.</SCNDESCR>
<PLAYSUBT>HAMLET</PLAYSUBT>
<ACT><TITLE>ACT I</TITLE>
<SCENE><TITLE>SCENE I. Elsinore. A platform before the castle.</TITLE>
<STAGEDIR>FRANCISCO at his post. Enter to him BERNARDO</STAGEDIR>
<SPEECH>
<SPEAKER>BERNARDO</SPEAKER>
<LINE>Who's there?</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>FRANCISCO</SPEAKER>
<LINE>Nay, answer me: stand, and unfold yourself.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>BERNARDO</SPEAKER>
<LINE>Long live the king!</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>FRANCISCO</SPEAKER>
<LINE>Bernardo?</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>BERNARDO</SPEAKER>
<LINE>He.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>FRANCISCO</SPEAKER>
<LINE>You come most carefully upon your hour.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>BERNARDO</SPEAKER>
<LINE>'Tis now struck twelve; get thee to bed, Francisco.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>FRANCISCO</SPEAKER>
<LINE>For this relief much thanks: 'tis bitter cold,</LINE>
<LINE>And I am sick at heart.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>BERNARDO</SPEAKER>
<LINE>Have you had quiet guard?</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>FRANCISCO</SPEAKER>
<LINE>Not a mouse stirring.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>BERNARDO</SPEAKER>
<LINE>Well, good night.</LINE>
<LINE>If you do meet Horatio and Marcellus,</LINE>
<LINE>The rivals of my watch, bid them make haste.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>FRANCISCO</SPEAKER>
<LINE>I think I hear them. Stand, ho! Who's there?</LINE>
</SPEECH>
<STAGEDIR>Enter HORATIO and MARCELLUS</STAGEDIR>
<SPEECH>
<SPEAKER>HORATIO</SPEAKER>
<LINE>Friends to this ground.</LINE>
</SPEECH>
<SPEECH>
<SPEAKER>MARCELLUS</SPEAKER>
<LINE>And liegemen to the Dane.</LINE>
</SPEECH>
<STAGEDIR>Exeunt</STAGEDIR>
</SCENE>
</ACT>
</PLAY>
Shodan at 2007-12-5 14:10:43 >

# 4 Re: [RESOLVED] XML - getting a child to use a for-each loop
Your right...what a sneaky...!
Now I got to figure out how to match a persona text in order to display it right...this...
LUCIANUS, nephew to the king.
A Gentleman
A Priest.
FRANCISCO, a soldier.
REYNALDO, servant to Polonius.
Players.
Two Clowns, grave-diggers.
FORTINBRAS, prince of Norway.
A Captain.
English Ambassadors.
GERTRUDE, queen of Denmark, and mother to Hamlet.
OPHELIA, daughter to Polonius.
should be, I think
Lucianus, nephew to the king.
..
..
PLAYERS
Two Clowns, grave-diggers.
..
..
ENGLISH AMBASSADORS.
Gertrude, queen of Denmark, andmother to Hamlet.
...
Can I do something like if <persona> = players then all cap??
Shodan at 2007-12-5 14:12:48 >
