Xml 使用模式忽略XSLT模板中的子节点
我正在将一个XML文档转换为一个HTML文件,以便在线显示(作为一本电子书) XML文件中的每一章都包含在Xml 使用模式忽略XSLT模板中的子节点,xml,xslt,Xml,Xslt,我正在将一个XML文档转换为一个HTML文件,以便在线显示(作为一本电子书) XML文件中的每一章都包含在中,并有一个标题()。我需要将每个标题显示两次—一次作为目录的一部分,在开始时显示,第二次显示在每章的顶部。我在中使用了mode=“toc”来执行此操作 我的问题是,我的一些标题有一个子元素,其中包含编辑脚注。当标题出现在章节顶部时,我需要处理这些标记,但我不希望它们显示在目录中(即mode=“toc”) 我的问题是如何告诉样式表处理目录的元素,但忽略任何子元素(如果出现) 以下是一个没有注
中,并有一个标题(
)。我需要将每个标题显示两次—一次作为目录的一部分,在开始时显示,第二次显示在每章的顶部。我在
中使用了mode=“toc”
来执行此操作
我的问题是,我的一些
标题有一个子元素
,其中包含编辑脚注。当标题出现在章节顶部时,我需要处理这些
标记,但我不希望它们显示在目录中(即mode=“toc”
)
我的问题是如何告诉样式表处理目录的
元素,但忽略任何子元素(如果出现)
以下是一个没有注释的标题示例,在目录模式下显示良好:
<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>
我还尝试了tei:head/tei:note
和\\tei:head\tei:note
在与整个文档匹配的模板(/
)中,我使用以下内容显示目录:
<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:apply-templates select="//tei:head" mode="toc"/>
我尝试添加以下内容,但没有效果:
<xsl:apply-templates select="//tei:head/tei:note[@type = 'editorial']"
mode="toc"/>
任何帮助都将不胜感激
p、 这是我第一次在SE上发表文章,如果我遗漏了重要的细节,请让我知道,我会澄清。谢谢。在进行toc特定处理时,通常需要传递模式:
<xsl:template match="tei:head" mode="toc" />
<xsl:template match="tei:head[../@type = 'chapter']" mode="toc">
<h3><a href="#{../@xml:id}"><xsl:apply-templates mode="toc" /></a></h3>
</xsl:template>
你能给我们看一下你的完整XSLT(如果不是太大的话)和一个输入输出XML样本吗?太好了,谢谢你。一旦我添加了
mode=“toc”
到xsl:apply templates
,就像你的例子描述的那样,后面的空
使元素静音。太棒了!
<xsl:apply-templates select="//tei:head/tei:note[@type = 'editorial']"
mode="toc"/>
<xsl:template match="tei:head" mode="toc" />
<xsl:template match="tei:head[../@type = 'chapter']" mode="toc">
<h3><a href="#{../@xml:id}"><xsl:apply-templates mode="toc" /></a></h3>
</xsl:template>
<xsl:template match="tei:head" mode="toc" />
<xsl:template match="tei:head[../@type = 'chapter']" mode="toc">
<h3><a href="#{../@xml:id}">
<xsl:apply-templates select="node()[not(self::tei:note)]" />
</a></h3>
</xsl:template>