[英]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.