1
在下面的xml片段中,我有一個帶有腳註的部分和一個帶有腳註的小節。我想順序重新編排腳註開始在紙張/科級,儘管該FN的不是兄弟姐妹從祖先獲取後代節點的位置,不一定是兄弟
<?xml version='1.0' ?>
<paper>
<section>
<title>My Main Section</title>
<para>My para with a <footnote num="1">text</footnote> footnote.</para>
<section>
<title>my subsection</title>
<para>more text with another <footnote num="1">more fn text.</footnote> footnote.</para>
</section>
</section>
</paper>
預期的輸出將是:
<?xml version='1.0' ?>
<paper>
<section><title>My Main Section</title>
<para>My para with a <footnote num="1">text</footnote> footnote.</para>
<section><title>my subsection</title>
<para>more text with another <footnote num="2">more fn text.</footnote> footnote.</para>
</section>
</section>
</paper>
我試圖用各種各樣的東西xsl:號碼,但無法獲得任何工作。我能得到的最接近的是以下幾點:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="footnote/@num">
<xsl:attribute name="num"><xsl:value-of select="count(ancestor::paper/section//footnote)"/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
,讓2個正確的計數,但我不知道如何表示,「我的前兩個腳註在這個主要部分」。
我也試着寫了一個名爲模板,像這樣:
<xsl:template match="/paper/section">
<section>
<xsl:call-template name="renumberFNs"/>
<xsl:apply-templates/>
</section>
</xsl:template>
<xsl:template name="renumberFNs">
<xsl:for-each select=".//footnote/@num">
<xsl:attribute name="num"><xsl:value-of select="position()"/></xsl:attribute>
</xsl:for-each>
</xsl:template>
而是把@num的部分。有任何想法嗎?
「*重新編號從紙/科級開始的腳註,所以fn不是兄弟姐妹*」我不確定這是什麼意思。爲什麼不發佈轉換的預期結果? – 2015-03-31 16:02:08
增加了預期的輸出,併爲清晰度編輯(我希望:)) – badperson 2015-03-31 16:08:41