0

这是一个简化的 XML,它揭示了我遇到的问题的一般结构。

<chapter num="07">
    <title>
        <page num="703"/>
        ... text (mixed content) ...
    </title>

    <page num="704"/>
    <section level="sect1">
        <title>...text...</title>
        <para num="7.1.1">... a lot of text (mixed content)...</para>
    </section>
    <section level="sect1">
        <title>... text... </title>
        <para num="7.2.1">Some text...
            <footnoteref linkend="fn3" num="3"/>
            <footnote num="3" id="fn3"> ... mixed content ...</footnote> 
            ...more text...
        </para>

        <page num="705"/>
        <section level="sect2">
            <title>...</title>
            <para num="7.2.2">... text ...
                <footnoteref linkend="fn4" num="4"/>
                <footnote num="4" id="fn4">...</footnote> 
                ... more text ...
                <footnoteref linkend="fn5" num="5"/>
                <footnote num="5" id="fn5">...</footnote> 
                ... more text ...
            </para>
            <para num="7.2.5">...

                <page num="706"/>... 

                <footnoteref linkend="fn6" num="6"/>
                <footnote num="6" id="fn6"> ... </footnote>
            </para>
            <para num="7.2.6">... some text
                <footnoteref linkend="fn7" num="7"/>
                <footnote num="7" id="fn7"> ... </footnote>  
            </para>
        </section>
    </section>
</chapter>

我必须在第一个匹配最后一个之前放置一个处理指令<?pb label='页码。它应该只出现一次,并且页码应该与出现的最后一个元素的属性中的值相同。'?> <footnote><page>num<page>

例如,如果我处理上面的源代码,我希望在我的结果文档中生成一个紧接 <?pb label='704'?>在之前<footnote num="3">、紧接在之前(将脚注 4 和 5 分组)和紧接在之前(将脚注 6 和 7 分组)的结果文档。有一个模板来处理元素,它们一起放在每页的末尾,前面是处理指令(元素保持在它们所在的位置)。 <?pb label='705'?><footnote num="4"> <?pb label='706'?><footnote num="6"><footnote><footnoteref>

我的 XSL 在这里。由于它太大,我无法将其粘贴在这里。

我在脚注处理说明(pb 标签)中得到了重复。只有在footnote最后一个page标签之后的第一个标签之前应该有一个 pblabel。我尝试匹配preceding::page但没有用。相同的处理指令被重复多次。例如:<?pb label='706'?>应该只在上面出现一次,footnote 6因为它是footnote下面的第一个page 706

4

1 回答 1

1

如果不进行耗时的分析,很难判断,但请尝试更改此xsl:if(in match="footnote" mode="footnote"):

    <xsl:if test="preceding::node()[page[1]]">
        <xsl:variable name="op">&#60;</xsl:variable>
        <xsl:variable name="apos">'</xsl:variable>
        <xsl:variable name="cl">&#62;</xsl:variable>

        <xsl:value-of select="concat($op,'?pb label=',$apos,preceding::page[1]/@num,$apos,'?',$cl)"/>

    </xsl:if>

对此:

    <xsl:if test="(preceding::page|preceding::footnote)[last()][self::page]">
        <xsl:processing-instruction name="pb" select="concat('label=''',preceding::page[1]/@num,'''?')"/>
    </xsl:if>

有点奇怪,当您的输出方法是 HTML 时,您尝试输出 XML 处理指令(这将具有 SGML 处理指令)。

于 2014-05-08T15:20:26.797 回答