1
我有下面的XML。前面的元素計數忽略節點
<nd>
<fn>
<fnn>*</fnn>
<fnt>
<p>
<i>ftn 1</i>
</p>
</fnt>
</fn>
<ti>
<fn>
<fnn>*</fnn>
<fnt>
<p>
<i>ftn 1</i>
</p>
</fnt>
</fn>
</ti>
<tx>
<fn>
<fnn>1</fnn>
<fnt>
<p>
<i>ftn2</i>
</p>
</fnt>
</fn>
<fn>
<fnn>2</fnn>
<fnt>
<p>
<i>ftn3</i>
</p>
</fnt>
</fn>
</tx>
</nd>
在這裏,我要算前fnn
和創建腳註,但在這裏我想則會忽略的preceding::tx
。我正在使用下面的XSLT。
<xsl:template match="/">
<hmtl>
<head>
<title>New Version!</title>
</head>
<xsl:apply-templates/>
<xsl:if test="//fnn">
<section class="tr_footnotes">
<xsl:text disable-output-escaping="yes"><![CDATA[<hr />]]></xsl:text>
<xsl:apply-templates select="//page|//fnt" mode="footnote"/>
</section>
</xsl:if>
</hmtl>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="fnn">
<xsl:variable name="count" select="count(preceding::fnn)"/>
<xsl:variable name="varHeaderNote" select='concat("f",$count)'/>
<xsl:variable name="varFootNote" select='concat("#ftn.",$count)'/>
<sup>
<a name="{$varHeaderNote}" href="{$varFootNote}" class="tr_ftn">
<xsl:value-of select="."/>
</a>
</sup>
</xsl:template>
<xsl:template match="ti"/>
<xsl:template match="fnt" mode="footnote">
<xsl:variable name="count" select="count(preceding::fnn)"/>
<div class="tr_footnote">
<div class="footnote">
<sup>
<a>
<xsl:attribute name="name"><xsl:text>ftn.</xsl:text><xsl:value-of select="$count"/></xsl:attribute>
<xsl:attribute name="href"><xsl:text>#f</xsl:text><xsl:value-of select="$count"/></xsl:attribute>
<xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text></xsl:attribute>
<xsl:value-of select="$count"/>
</a>
</sup>
<xsl:apply-templates/>
</div>
</div>
</xsl:template>
這裏我可以在使用<xsl:template match="ti"/>
忽略ti
,但泰德指望它正在考慮內部ti
的fnn
,在這裏,我想忽略它和計數。而在腳註部分,我無法忽視它。
在這裏頭部分。
ftn.0
後,將其產生ftn.2
,但我想這是ftn 1
而在腳註部分有ftn.1
和ftn.2
(這是ti
腳註),這應該被忽略。
請讓我知道我該如何解決這個問題。
這裏是working Demo
感謝。
這不是在腳註部分 – user3872094
工作我不知道理解完全地將OBJECTIF,但試試這個方法:http://xsltransform.net/6qVRKww/8。它當然有一個更簡單的方法,但它不需要更改整個代碼。有必要改變計數器並將其推導爲模式腳註的模板,並對fnt進行謂詞。 –