首先,我試圖在XSLT,XPath和XSL-FO的幫助下從XML創建PDF。如何用XSLT/XSL-FO壓縮相同的腳註?
我有一個帶有多個腳註的XML,我使用一個模板在標籤名稱「note」後自動呈現它們。
XML:
<document>
<ul type='custom-list-1' startdist="0.5cm" gap="0.15cm">
<li space-before="30pt">
List-item 1
<block margin-left="-15pt" margin-right="-15pt" text-align="center">
<table layout="fixed" width="100%">
<col number="1" width="30%" />
<col number="2" width="17%" />
<col number="3" width="17%" />
<col number="4" width="17%" />
<col number="5" width="17%" />
<tbody>
<tr font-style="italic">
<th>sample title</th>
<th colspan="4">sample title</th>
</tr>
<tr>
<td>
Bla bla bla
<note name="name-1">
Footnote for "bla bla bla"
</note>
</td>
<td colspan="4">
.............
</td>
</tr>
<tr>
<td>
Comision Administrare Online Banking
</td>
<td colspan="4">
.........
</td>
</tr>
<tr>
<td>
Another... Bla bla bla
<note name="name-2">
Footnote for "Another... Bbla bla bla"
</note>
</td>
<td colspan="4">
......
</td>
</tr>
</tbody>
</table>
</block>
</li>
<li space-before="30pt">List-item 2:
<block margin-left="-15pt" text-align="center">
<table layout="fixed" width="100%">
<col number="1" width="18%" />
<col number="2" width="13%" />
<col number="3" width="13%" />
<col number="4" width="16%" />
<col number="5" width="13%" />
<col number="6" width="13%" />
<col number="7" width="13%" />
<tbody>
<tr font-style="italic">
<th colspan="2" rowspan="2">Sample title</th>
<th colspan="2">Sample title</th>
<th rowspan="2">Sample title</th>
<th rowspan="2">Sample title</th>
<th rowspan="2">Sample title</th>
</tr>
<tr font-style="italic">
<th>Min</th>
<th>Max</th>
</tr>
<tr>
<td colspan="2">Some text here</td>
<td colspan="2">
1%
<note name="name-3">
Footnote for "1%"
</note>
/0.5%
<note name="name-4">
Footnote for "0.5%"
</note>
</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td colspan="2">Sample text</td>
<td colspan="2">
1%
<note name="name-3">
Footnote for "1%"
</note>
/0.5%
<note name="name-4">
Footnote for "0.5%"
</note>
</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td colspan="2">Sample text</td>
<td colspan="2">
1%
<note name="name-3">
Footnote for "1%"
</note>
/0.5%
<note name="name-4">
Footnote for "0.5%"
</note>
</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
</table>
</block>
</li>
<li space-before="30pt">List-item 3
<block margin-left="-15pt" text-align="center">
<table layout="fixed" width="100%">
<col number="1" width="25%" />
<col number="2" width="15%" />
<col number="3" width="15%" />
<col number="4" width="22%" />
<col number="5" width="22%" />
<tbody>
<tr font-style="italic">
<th colspan="2">Sample title</th>
<th></th>
<th>Sample title</th>
<th>Sample title</th>
</tr>
<tr>
<td colspan="2">Sample text</td>
<td></td>
<td>0%</td>
<td>0%</td>
</tr>
<tr>
<td colspan="2">Sample text</td>
<td></td>
<td>0.05%<note name="name-5">Footnote for "0.05%"</note></td>
<td>0.05%</td>
</tr>
<tr>
<td colspan="2">Sample text</td>
<td></td>
<td>0%</td>
<td>0%</td>
</tr>
</tbody>
</table>
</block>
</li>
</ul>
XSLT:
<xsl:attribute-set name="note.data" >
<xsl:attribute name="text-align">justify</xsl:attribute>
<xsl:attribute name="font-weight">normal</xsl:attribute>
</xsl:attribute-set>
<xsl:key name="by-name" match="//note[@name]" use="@name" />
<xsl:template match="note">
<xsl:call-template name="note" />
</xsl:template>
<xsl:template name="note">
<xsl:param name="unique-elements"
select="current()[generate-id(.) = generate-id(key('by-name', @name)[1])]"/>
<xsl:param name="identical-elements"
select="current()[not(generate-id(.) = generate-id(key('by-name', @name)[1]))]"/>
<xsl:if test="$unique-elements">
<xsl:variable name="element" select="$unique-elements"/>
<fo:footnote>
<fo:inline baseline-shift="super" font-size="75%" color="red">
<xsl:number level="any" count="//note[generate-id(.) = generate-id(key('by-name', @name)[1])]" format="(1)" />
</fo:inline>
<fo:footnote-body xsl:use-attribute-sets="note.data">
<fo:block color="blue">
<fo:inline baseline-shift="super" font-size="75%">
<xsl:number level="any" count="//note[generate-id(.) = generate-id(key('by-name', @name)[1])]" format="(1)" />
</fo:inline>
<xsl:value-of select="$element" />
</fo:block>
</fo:footnote-body>
</fo:footnote>
</xsl:if>
<xsl:if test="$identical-elements">
<fo:inline baseline-shift="super" font-size="75%" color="green">
<xsl:number level="any" count="//note[generate-id(.) = generate-id(key('by-name', @name)[1])]" format="(1)" />
</fo:inline>
</xsl:if>
</xsl:template>
PDF輸出:
因此,我設法壓制相同的腳註並保持唯一腳註的計數(圖像用紅色着色),併爲相同的腳註(用綠色着色的圖像)添加最後的計數值。
現在的問題是,我無法弄清楚如何爲相同的腳註保持相同的計數值。
在此先感謝!
您想在哪裏放置select語句?或者應該是匹配語句並替換你的''?你也可以展示你的一些源代碼XML,也許更多的是你的樣式表,這可能與模板應用在哪裏有所不同。 –
@TobiasKlevenz - 我編輯了這篇文章。現在我認爲足以做出一個想法......謝謝。 –
對不起,我還是不太明白你想要的輸出是什麼。我的猜測是你想要繼續計算相同的腳註,所以綠色4將是5,6,7,8,並且比你的頁腳線更適合那些閱讀(4)(5)(6)(7)(8)腳註「0,5%」......這是正確的嗎? –