[英]Transform an HTML DL into 2-column XSL-FO table of terms and definitions
如何使用XSLT將HTML定義列表(DL)轉換為兩列的XSL-FO表,其中第一列為術語,第二列為定義,並且可能有多個定義?
(如果已經在某個地方回答了,則表示歉意。我搜索了但沒有找到。)
這個問題的關鍵在於找到仍將當前DT作為其術語的以下兄弟姐妹 : XSLT:選擇以下兄弟姐妹直到到達指定標簽
然后,只需將整個表定義為頂級DL模板即可:
<xsl:template match="dl">
<fo:table>
<fo:table-body>
<xsl:for-each select="dt">
<xsl:variable name="current-term" select="."/>
<fo:table-row>
<fo:table-cell font-weight="bold" width="5.5cm">
<fo:block>
<xsl:apply-templates />
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:apply-templates select="following-sibling::dd[preceding-sibling::dt[1] = $current-term]" />
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="dd">
<fo:block>
<xsl:apply-templates />
</fo:block>
</xsl:template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.