XSLT 中的拆分表 [英] Split Table in XSLT
本文介绍了XSLT 中的拆分表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 XML,我需要将它分成 50 或 100 行,XML 看起来像这样.
I Have a XML that i need to split it by 50 or 100 rows the XML looks like this.
<?xml version = "1.0" encoding = "utf-8" standalone = "yes"?>
<DOCUMENT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<A>
<B>
<C>
<D>
<ROW>
<SNo>1</SNo>
<Date>06/JUN/2014</Date>
<Time>12:31:49</Time>
</ROW>
<ROW>
<SNo>2</SNo>
<Date>07/JUN/2014</Date>
<Time>11:50:42</Time>
</ROW>
</D>
<D>
<ROW>
<SNo>3</SNo>
<Date>08/JUN/2014</Date>
<Time>19:43:09</Time>
</ROW>
<ROW>
<SNo>4</SNo>
<Date>10/JUN/2014</Date>
<Time>08:26:07</Time>
</ROW>
</D>
</C>
</B>
</A>
</DOCUMENT>
我尝试过使用如下所示的 position() mod
I Have tried using the position() mod like below
ROW[ position() mod 50 =1 ]
following-sibling::ROW[ position() < 50 ]
我需要像下面这样的输出
I need a output like below
<?xml version = "1.0" encoding = "utf-8" standalone = "yes"?>
<DOCUMENT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<A>
<B>
<C>
<D>
<ROW>
<SNo>1</SNo>
<Date>06/JUN/2014</Date>
<Time>12:31:49</Time>
</ROW>
<ROW>
<SNo>2</SNo>
<Date>07/JUN/2014</Date>
<Time>11:50:42</Time>
</ROW>
<ROW>
<SNo>3</SNo>
<Date>08/JUN/2014</Date>
<Time>19:43:09</Time>
</ROW>
<ROW>
<SNo>4</SNo>
<Date>10/JUN/2014</Date>
<Time>08:26:07</Time>
</ROW>
.
.
.
.
.
<ROW>
<SNo>50</SNo>
<Date>08/JUN/2014</Date>
<Time>19:43:09</Time>
</ROW>
</D>
<D>
<ROW>
<SNo>1</SNo>
<Date>08/JUN/2014</Date>
<Time>19:43:09</Time>
</ROW>
<ROW>
<SNo>2</SNo>
<Date>10/JUN/2014</Date>
<Time>08:26:07</Time>
</ROW>
.
.
.
.
.
<ROW>
<SNo>50</SNo>
<Date>10/JUN/2014</Date>
<Time>08:26:07</Time>
</ROW>
</D>
</C>
</B>
</A>
</DOCUMENT>
但是好像不行.任何人都可以检查一下并帮助我...
But it does not seem to work. Can anyone have a check on this and help me...
推荐答案
当您使用 XSLT 2.0 时,您可以简单地使用 for-each-group,例如
As you use XSLT 2.0, you can simply use for-each-group e.g.
<xsl:param name="size" as="xs:integer" select="50"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* , node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="C">
<xsl:copy>
<xsl:for-each-group select="D/ROW" group-adjacent="(position() - 1) idiv $size">
<D>
<xsl:apply-templates select="current-group()"/>
</D>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
<xsl:template match="ROW">
<xsl:copy>
<SNo><xsl:value-of select="position()"/></SNo>
<xsl:apply-templates select="node() except SNo"/>
</xsl:copy>
</xsl:template>
这篇关于XSLT 中的拆分表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文