2
基本上,這是我從莎士比亞的摘錄採取XML玩:XSL的for-each循環
<PLAY>
<PERSONA>BENEDICK, a young lord of Padua.</PERSONA>
<PERSONA>LEONATO, governor of Messina.</PERSONA>
<PERSONA>ANTONIO, his brother.</PERSONA>
<PERSONA>BALTHASAR, attendant on Don Pedro.</PERSONA>
<PGROUP>
<PERSONA>CONRADE</PERSONA>
<PERSONA>BORACHIO</PERSONA>
<GRPDESCR>followers of Don John.</GRPDESCR>
</PGROUP>
<PERSONA>FRIAR FRANCIS</PERSONA>
</PLAY>
這裏的XSL:
<xsl:template match="PLAY">
<html>
<body>
<xsl:for-each select="PERSONAE">
<xsl:apply-templates select="PERSONA" />
<xsl:apply-templates select="PGROUP/PERSONA" />
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="PERSONA">
<p><xsl:value-of select="." /></p>
</xsl:template>
<xsl:template match="PGROUP/PERSONA">
<xsl:for-each select=".">
<p><xsl:value-of select="." />, </p>
</xsl:for-each>
<xsl:for-each select="..">
<p><xsl:value-of select="GRPDESCR" /></p>
</xsl:for-each>
</xsl:template>
目前的HTML輸出:
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.
這就是我想讓我的HTML輸出看起來像:
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.
我在這個上花了好幾個小時,所以任何幫助都會很棒!
你先生,是一個天才。非常感謝! – Encephalon