xml - Ignore child nodes in XSLT template using mode -
i'm transforming xml document html file online display (as electronic book).
each chapter in xml file contained within <div>
, has heading (<head>
). need display each heading twice - once part of table of contents @ start, second time @ top of each chapter. i've used mode="toc"
within <xsl:template>
this.
my problem few of <head>
headings have child element <note>
, contain editorial footnotes. need these <note>
tags processed when headings appear @ top of chapters, don't want them show in table of contents (i.e. when mode="toc"
.
my question how tell stylesheet process <head>
elements table of contents, ignore child elements (should occur)?
here's example heading without note, displays fine in table of contents mode:
<div xml:id="d1.c1" type="chapter"> <head>pursuit of pleasure. limits set virtue— asceticism vice</head> <p>contents of chapter 1 go here</p> </div>
and here's 1 note, want stripped out when generating table of contents:
<div xml:id="d1.c6" type="chapter"> <head>happiness , virtue, how diminished asceticism in indirect way.—useful , genuine obligations elbowed out spurious ones<note xml:id="d1.c6fn1" type="editor">in text, author has noted @ point: 'these topics must have been handled elsewhere: perhaps gone through with. yet follows may serve introduction.'</note></head> <p>contents of chapter 6 go here</p> </div>
my xsl looks this:
<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>
i've tried adding new blank template match in toc
mode note, no avail. example:
<xsl:template match="tei:note" mode="toc"/>
i've tried tei:head/tei:note
, \\tei:head\tei:note
in template matches whole document (/
), use following display table of contents:
<xsl:apply-templates select="//tei:head" mode="toc"/>
i've tried adding following, no avail:
<xsl:apply-templates select="//tei:head/tei:note[@type = 'editorial']" mode="toc"/>
any appreciated!
p.s. first ever post on se, if have missed out important details please let me know , i'll clarify. thanks.
you typically need pass mode along when doing toc-specific processing:
<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>
note mode
attribute on xsl:apply-templates
. if that, template tei:note
should obeyed.
if you're using identity template, mean need 1 toc
mode.
alternatively, if don't need mode-specific processing once you've reached tei:head
, can this:
<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>