从多个 for-each XSLT 段输出 HTML
Outputting HTML from multiple for-each XSLT segments
我想显示一个特定字符的所有行
舞台剧。为此,我需要嵌套多个 for-each 语句以
得出正确的数据。
我正在使用的 XML 文件的摘录:
<TEI xml:id="E850003-105">
<text n="E850003-105">
<front>
<pb n="370"/>
<div>
<head>The persons of the play</head>
<list>
<item>LORD WINDERMERE.</item>
<item>LORD DARLINGTON.</item>
<item>LORD AUGUSTUS LORTON.</item>
<item>MR. DUMBY.</item>
<item>MR. CECIL GRAHAM.</item>
<item>MR. HOPPER.</item>
<item>PARKER, Butler.</item>
</list>
<list>
<item>LADY WINDERMERE.</item>
<item>THE DUCHESS OF BERWICK.</item>
<item>LADY AGATHA CARLISLE.</item>
<item>LADY PLYMDALE.</item>
<item>LADY STUTFIELD.</item>
<item>LADY JEDBURGH.</item>
<item>MRS. COWPER-COWPER.</item>
<item>MRS. ERLYNNE.</item>
<item>ROSALIE, Maid.</item>
</list>
</div>
</front>
<body>
<head>Lady Windermere's Fan</head>
<div1 n="1" type="act">
<head>ACT ONE</head>
<stage type="setting">SCENE:<view>
<emph>Morning-room of Lord Windermere's house in Carlton House Terrace,
London. The action of the play takes place within twenty-four hours,
beginning on a Tuesday afternoon at five o'clock, and ending the next
day at 1.30 p.m. TIME: The present. Doors C. and R. Bureau with books
and papers R. Sofa with small tea-table L. Window opening on to terrace
L. Table R. LADY WINDERMERE is at table R., arranging roses in a blue
bowl.</emph>
</view>
</stage>
<stage type="entrance">
<emph>Enter</emph> PARKER.</stage>
<sp>
<speaker>PARKER</speaker>
<p>Is your ladyship at home this afternoon?</p>
</sp>
我需要输出达林顿勋爵所说的所有台词,意思是
sp 元素中的扬声器元素需要具有该值。到目前为止我
在我的 xsl 文件中有此代码:
<xsl:template match="/">
<html>
<head>
<title>LORD DARLINGTON LINES</title>
</head>
<body>
<ul>
<xsl:for-each select="/TEI/text/body/div1">
<xsl:for-each select="stage">
<xsl:for-each select="sp[speaker = 'LORD DARLINGTON']">
<li><xsl:value-of select="p"/></li>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
但是对于我的输出,我只得到一个带有空 ul 标签的 body 标签。我看不出我的代码有什么问题。在 XSLT 中嵌套这样的 for-each 循环会不会出现意想不到的问题?
这不简单吗:
<xsl:template match="/">
<html>
<head>
<title>LORD DARLINGTON LINES</title>
</head>
<body>
<ul>
<xsl:for-each select="//sp[speaker = 'LORD DARLINGTON']">
<li><xsl:value-of select="p"/></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
我想显示一个特定字符的所有行 舞台剧。为此,我需要嵌套多个 for-each 语句以 得出正确的数据。
我正在使用的 XML 文件的摘录:
<TEI xml:id="E850003-105">
<text n="E850003-105">
<front>
<pb n="370"/>
<div>
<head>The persons of the play</head>
<list>
<item>LORD WINDERMERE.</item>
<item>LORD DARLINGTON.</item>
<item>LORD AUGUSTUS LORTON.</item>
<item>MR. DUMBY.</item>
<item>MR. CECIL GRAHAM.</item>
<item>MR. HOPPER.</item>
<item>PARKER, Butler.</item>
</list>
<list>
<item>LADY WINDERMERE.</item>
<item>THE DUCHESS OF BERWICK.</item>
<item>LADY AGATHA CARLISLE.</item>
<item>LADY PLYMDALE.</item>
<item>LADY STUTFIELD.</item>
<item>LADY JEDBURGH.</item>
<item>MRS. COWPER-COWPER.</item>
<item>MRS. ERLYNNE.</item>
<item>ROSALIE, Maid.</item>
</list>
</div>
</front>
<body>
<head>Lady Windermere's Fan</head>
<div1 n="1" type="act">
<head>ACT ONE</head>
<stage type="setting">SCENE:<view>
<emph>Morning-room of Lord Windermere's house in Carlton House Terrace,
London. The action of the play takes place within twenty-four hours,
beginning on a Tuesday afternoon at five o'clock, and ending the next
day at 1.30 p.m. TIME: The present. Doors C. and R. Bureau with books
and papers R. Sofa with small tea-table L. Window opening on to terrace
L. Table R. LADY WINDERMERE is at table R., arranging roses in a blue
bowl.</emph>
</view>
</stage>
<stage type="entrance">
<emph>Enter</emph> PARKER.</stage>
<sp>
<speaker>PARKER</speaker>
<p>Is your ladyship at home this afternoon?</p>
</sp>
我需要输出达林顿勋爵所说的所有台词,意思是 sp 元素中的扬声器元素需要具有该值。到目前为止我 在我的 xsl 文件中有此代码:
<xsl:template match="/">
<html>
<head>
<title>LORD DARLINGTON LINES</title>
</head>
<body>
<ul>
<xsl:for-each select="/TEI/text/body/div1">
<xsl:for-each select="stage">
<xsl:for-each select="sp[speaker = 'LORD DARLINGTON']">
<li><xsl:value-of select="p"/></li>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
但是对于我的输出,我只得到一个带有空 ul 标签的 body 标签。我看不出我的代码有什么问题。在 XSLT 中嵌套这样的 for-each 循环会不会出现意想不到的问题?
这不简单吗:
<xsl:template match="/">
<html>
<head>
<title>LORD DARLINGTON LINES</title>
</head>
<body>
<ul>
<xsl:for-each select="//sp[speaker = 'LORD DARLINGTON']">
<li><xsl:value-of select="p"/></li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>