CALS表格PDF视图边框缺失,如何用XSLT处理rowsep/colsep属性?
rowsep and colsep in XSLT for PDF Output Hey there! Let's tackle how to make those table borders show up correctly in your PDF, even with frame="none" set on your CALS table. The rowsep and colsep attributes are key here—they control whether individual cell borders are visible, and we can map them directly to XSL-FO (since you're generating PDF) border properties.
First, a quick recap of what these attributes do
rowsep="1": The cell should display a bottom border (separating it from the row below).rowsep="0"hides this border.colsep="1": The cell should display a right border (separating it from the next column).colsep="0"hides this border.
XSLT Template to Handle Borders
Since you're working with XSL-FO for PDF, here's a practical template that processes each <entry> element and applies borders based on these attributes:
<xsl:template match="entry"> <fo:table-cell> <!-- Set bottom border based on rowsep --> <xsl:attribute name="border-bottom"> <xsl:choose> <xsl:when test="@rowsep = '1'">solid 1pt #000</xsl:when> <xsl:otherwise>none</xsl:otherwise> </xsl:choose> </xsl:attribute> <!-- Set right border based on colsep --> <xsl:attribute name="border-right"> <xsl:choose> <xsl:when test="@colsep = '1'">solid 1pt #000</xsl:when> <xsl:otherwise>none</xsl:otherwise> </xsl:choose> </xsl:attribute> <!-- Optional: Add top border for the first row of thead --> <xsl:if test="parent::row[position() = 1 and ancestor::thead]"> <xsl:attribute name="border-top">solid 1pt #000</xsl:attribute> </xsl:if> <!-- Optional: Add left border for the first column --> <xsl:if test="position() = 1"> <xsl:attribute name="border-left">solid 1pt #000</xsl:attribute> </xsl:if> <!-- Render cell content --> <fo:block> <xsl:apply-templates/> </fo:block> </fo:table-cell> </xsl:template>
Key Notes for Edge Cases
- Cross-row cells (
morerows): If an entry has@morerows="n", adjust the bottom border logic to only show it on the last row the cell spans:<xsl:when test="@rowsep = '1' and (not(@morerows) or parent::row[position() = current()/@morerows + 1])"> solid 1pt #000 </xsl:when> - Customize border styles: Tweak
solid 1pt #000to match your desired thickness, style (dashed, dotted), and color. - Table-level border override: Ensure your root
<fo:table>element hasborder="none"to respect theframe="none"setting from your CALS XML.
Final Checks
Wrap this template into your existing XSL-FO stylesheet, make sure your main table template outputs an <fo:table> with no outer border, and you'll get a table that strictly follows the rowsep and colsep rules from your original XML.
内容的提问来源于stack exchange,提问作者Rajarampandian

