且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将大表拆分为几个小表

更新时间:2023-01-24 19:25:10

这是针对此类问题的经典 XSLT 1.0 解决方案:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:param name="prowLimit" select="12"/>

    <xsl:variable name="vTable" select="/*"/>

 <xsl:template match="node()|@*" name="identity">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>

 <xsl:template match="tr">
  <xsl:if test="position() mod $prowLimit = 1">
    <table>
      <xsl:copy-of select="$vTable/@*"/>
      <xsl:copy-of select=
      ". | following-sibling::tr[not(position() > $prowLimit -1)]"/>
    </table>
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>