【发布时间】:2013-04-25 15:10:24
【问题描述】:
我正在将 XML 文档转换为 HTML 文件以供在线显示(作为电子书)。
XML 文件中的每一章都包含在<div> 中,并有一个标题 (<head>)。我需要将每个标题显示两次——一次作为目录的一部分在开头,第二次在每章的顶部。我在<xsl:template> 中使用了mode="toc" 来执行此操作。
我的问题是我的一些<head> 标题有一个子元素<note>,其中包含编辑脚注。当标题出现在章节顶部时,我需要处理这些 <note> 标签,但我不希望它们显示在目录中(即当 mode="toc" 时。
我的问题是如何告诉样式表处理目录的<head> 元素,但忽略任何子元素(应该出现)?
这是一个没有注释的示例标题,在目录模式下可以正常显示:
<div xml:id="d1.c1" type="chapter">
<head>Pursuit of pleasure. Limits set to it by Virtue—
Asceticism is Vice</head>
<p>Contents of chapter 1 go here</p>
</div>
这里有一个注释,我想在生成目录时去掉它:
<div xml:id="d1.c6" type="chapter">
<head>Happiness and Virtue, how diminished by Asceticism in an indirect
way.—Useful and genuine obligations elbowed out by spurious ones<note
xml:id="d1.c6fn1" type="editor">In the text, the author has noted at this
point: 'These topics must have been handled elsewhere: perhaps gone through
with. Yet what follows may serve for an Introduction.'</note></head>
<p>Contents of chapter 6 go here</p>
</div>
我的 XSL 目前看起来像这样:
<xsl:template match="tei:head" mode="toc">
<xsl:if test="../@type = 'chapter'">
<h3><a href="#{../@xml:id}"><xsl:apply-templates/></a></h3>
</xsl:if>
</xsl:template>
我尝试在toc 模式下添加一个新的空白模板匹配以供备注,但无济于事。例如:
<xsl:template match="tei:note" mode="toc"/>
我也试过tei:head/tei:note和\\tei:head\tei:note
在匹配整个文档 (/) 的模板中,我使用以下内容显示目录:
<xsl:apply-templates select="//tei:head" mode="toc"/>
我尝试添加以下内容,但无济于事:
<xsl:apply-templates select="//tei:head/tei:note[@type = 'editorial']"
mode="toc"/>
任何帮助将不胜感激!
附言这是我第一次在 SE 上发帖,所以如果我错过了重要的细节,请告诉我,我会澄清的。谢谢。
【问题讨论】:
-
您能否向我们展示您的完整 XSLT(如果它不是太大的话)以及示例输入和输出 XML?