如何使用xslt对下列情况执行表分页?



输入图片描述

我想使用xslt对这个表进行分页,以便最后两个p元素和前两个p元素应该在一起。

我的输入xml有点像这样:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<table>
<tgroup>
<row>
<entry>Parameter</entry>
<entry>Description</entry>
</row>

<row>
<entry>A</entry>
<entry><p>A1</p>
<p>A2</p>
<p>A3</p>
<p>A4</p>
<p>A5</p>
</entry>
</row>

<row>
<entry>B</entry>
<entry><p>B1</p>
<p>B2</p>
<p>B3</p>
<p>B4</p>
<p>B5</p>
</entry>
</row>
</tgroup>
</table>

我想自动添加输出类属性到p元素分页,如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<table>
<tgroup>
<row>
<entry>Parameter</entry>
<entry>Description</entry>
</row>

<row>
<entry>A</entry>
<entry><p>A1</p>
<p>A2 outputclass="keep-with-previous"</p>
<p>A3</p>
<p>A4 outputclass="keep-with-next"</p>
<p>A5</p>
</entry>
</row>

<row>
<entry>B</entry>
<entry><p>B1</p>
<p>B2 outputclass="keep-with-previous"</p>
<p>B3</p>
<p>B4 outputclass="keep-with-next"</p>
<p>B5</p>
</entry>
</row>
</tgroup>
</table>

我的css如下:

@media print 
{ *[outputclass~="keep-with-next"] { page-break-after: avoid; } 
*[outputclass~="keep-with-previous"] { page-break-before: avoid; } 
*[outputclass~="top-of-page"] { page-break-before: always; } }

您可能需要以下两个模板:

<xsl:template match="row/entry[2]/p[2]">
<p outputclass="keep-with-previous" >
<xsl:apply-templates/>
</p>
</xsl:template>

<xsl:template match="row/entry[2]/p[4]">
<p outputclass="keep-with-next">
<xsl:apply-templates/>
</p>
</xsl:template>

相关内容

  • 没有找到相关文章

最新更新