从多个for-each XSLT段输出HTML
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从多个for-each XSLT段输出HTML相关的知识,希望对你有一定的参考价值。
我想在舞台剧中展示特定角色的所有线条。为此,我需要嵌套多个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>
我需要输出Lord Darlington所说的所有行,这意味着sp元素中的speaker元素需要具有该值。到目前为止,我在我的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中为这样的每个循环嵌套时是否会出现任何意外问题?
答案
这不是简单的:
<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 XSLT段输出HTML的主要内容,如果未能解决你的问题,请参考以下文章
XSLT - 在嵌套的 for-each 中查找 position()
有没有办法在 XSLT 转换中用应用模板替换 for-each?