匹配以下内容并调用模板 [英] matching the following and call template
问题描述
这是一个简化的XML,它暴露了我所遇到的问题的一般结构.
This is a simplified XML which exposes the general structure of the problem I have.
<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>
我必须在第一个<footnote>
之前的最后一个<page>
之前放置一个处理指令<?pb label='
页码 '?>
.它应该只出现一次,并且页码应该与出现的最后一个<page>
元素的num
属性中的值相同.
I have to place one processing instruction <?pb label='
page number'?>
before the first <footnote>
matching the last preceding <page>
. It should appear only once and the page number should be the same as the value in the num
attribute of the last <page>
element that appeared.
例如,如果我处理上述源代码,我希望在结果文档 one <?pb label='704'?>
中紧接在<footnote num="3">
之前, one <?pb label='705'?>
中生成在<footnote num="4">
之前(将脚注4和5分组),以及在<footnote num="6">
之前的 one <?pb label='706'?>
(将脚注6和7分组).有一个用于处理<footnote>
元素的模板,它们被放置在每页的末尾,并带有处理指令(<footnoteref>
元素保留在它们所在的位置).
For example, if I process the source above, I expect to generate in my result document one <?pb label='704'?>
immediately before <footnote num="3">
, one <?pb label='705'?>
immediately before <footnote num="4">
(grouping footnotes 4 and 5), and one <?pb label='706'?>
immediately before <footnote num="6">
(grouping footnotes 6 and 7). There is a template to process the <footnote>
elements and they are placed together at the end of each page, preceded by the processing instruction (the <footnoteref>
elements stay where they are).
我的XSL在此处.由于太大,我无法将其粘贴到这里.
My XSL is here. Since it is too big, I'm unable to paste it here.
我在脚注处理说明(pb标签)中得到了重复.仅在最后一个page
标记之后的第一个footnote
之前应该有一个pblabel.我尝试与preceding::page
匹配,但是没有用.相同的处理指令被重复多次.例如:<?pb label='706'?>
应该仅在footnote 6
上方出现一次,因为它是page 706
之后的第一个footnote
.
I'm getting duplicates in the footnote processing instructions (the pb labels). There should be a pblabel only before the first footnote
following the last page
tag. I tried matching with preceding::page
but it didn't work. The the same processing instruction is being repeated multiple times. For example: <?pb label='706'?>
should appear only once above footnote 6
because it is the first footnote
following page 706
.
推荐答案
不进行费时的分析就很难分辨,但是请尝试更改此xsl:if
(在match="footnote" mode="footnote"
中):
It's hard to tell without doing a time consuming analysis, but try changing this xsl:if
(in match="footnote" mode="footnote"
):
<xsl:if test="preceding::node()[page[1]]">
<xsl:variable name="op"><</xsl:variable>
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="cl">></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>
Kinda感到奇怪的是,当您的输出方法是HTML(具有SGML处理指令)时,您试图输出XML处理指令.
Kinda strange that you're trying to output XML processing instructions when your output method is HTML (which would have SGML processing instructions).
这篇关于匹配以下内容并调用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!