从多个for-each XSLT段输出HTML

问题描述 投票:0回答:1

我想在舞台剧中展示特定角色的所有线条。为此,我需要嵌套多个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中为这样的每个循环嵌套时是否会出现任何意外问题?

xml xslt tei
1个回答
1
投票

这不是简单的:

    <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>
© www.soinside.com 2019 - 2024. All rights reserved.