Xml 将子节点分组为一组4
我有以下XSLT,我使用的是标识转换,因为我需要保持xml的完整性,并且只更改xml的特定部分,即Xml 将子节点分组为一组4,xml,xslt,Xml,Xslt,我有以下XSLT,我使用的是标识转换,因为我需要保持xml的完整性,并且只更改xml的特定部分,即 转变 <committee committeetype="Associate"> <affiliation dbid="11"> <name>Eve </name> </affiliation> <affiliation dbid="12"> <name>
转变
<committee committeetype="Associate">
<affiliation dbid="11">
<name>Eve </name>
</affiliation>
<affiliation dbid="12">
<name>Dan </name>
</affiliation>
<affiliation dbid="13">
<name>Harold </name>
</affiliation>
<affiliation dbid="14">
<name>Chris </name>
</affiliation>
<affiliation dbid="25">
<name>Malcolm </name>
</affiliation>
<affiliation dbid="15">
<name>Mike </name>
</affiliation>
</committee>
前夕
丹
哈罗德
克里斯
马尔科姆
迈克
进入
前夕
丹
哈罗德
克里斯
马尔科姆
迈克
我如何才能使其将从属关系分为4个
比如
<committee committeetype="Associate">
<affiliation dbid="11">
<name>Eve </name>
</affiliation>
<affiliation dbid="12">
<name>Dan </name>
</affiliation>
<affiliation dbid="13">
<name>Harold </name>
</affiliation>
<affiliation dbid="14">
<name>Chris </name>
</affiliation>
</committee>
<committee committeetype="Associate">
<affiliation dbid="25">
<name>Malcolm </name>
</affiliation>
<affiliation dbid="15">
<name>Mike </name>
</affiliation>
</committeemembergroup>
前夕
丹
哈罗德
克里斯
马尔科姆
迈克
提前感谢。这里有一个建议可能就足够了:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="chunk-size" select="4"/>
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<!--Identity Transform.-->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="committee[@committeetype='Associate']">
<xsl:apply-templates select="affiliation[position() mod $chunk-size = 1]" mode="group"/>
</xsl:template>
<xsl:template match="committee[@committeetype='Associate']/affiliation" mode="group">
<committee committeetype="Associate">
<xsl:apply-templates select=". | following-sibling::affiliation[position() < $chunk-size]"/>
</committee>
</xsl:template>
</xsl:stylesheet>
它转变
<committee committeetype="Associate">
<affiliation dbid="11">
<name>Eve </name>
</affiliation>
<affiliation dbid="12">
<name>Dan </name>
</affiliation>
<affiliation dbid="13">
<name>Harold </name>
</affiliation>
<affiliation dbid="14">
<name>Chris </name>
</affiliation>
<affiliation dbid="25">
<name>Malcolm </name>
</affiliation>
<affiliation dbid="15">
<name>Mike </name>
</affiliation>
</committee>
前夕
丹
哈罗德
克里斯
马尔科姆
迈克
进入
前夕
丹
哈罗德
克里斯
马尔科姆
迈克
但是,我不知道您的委员会
元素是否有除上述样式表过程中的附属
元素之外的其他子元素。如果需要更多的代码
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="chunk-size" select="4"/>
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<!--Identity Transform.-->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="committee[@committeetype='Associate']">
<xsl:apply-templates select="affiliation[position() mod $chunk-size = 1]" mode="group"/>
</xsl:template>
<xsl:template match="committee[@committeetype='Associate']/affiliation" mode="group">
<committee committeetype="Associate">
<xsl:apply-templates select=". | following-sibling::affiliation[position() < $chunk-size]"/>
</committee>
</xsl:template>
</xsl:stylesheet>
<committee committeetype="Associate">
<affiliation dbid="11">
<name>Eve </name>
</affiliation>
<affiliation dbid="12">
<name>Dan </name>
</affiliation>
<affiliation dbid="13">
<name>Harold </name>
</affiliation>
<affiliation dbid="14">
<name>Chris </name>
</affiliation>
<affiliation dbid="25">
<name>Malcolm </name>
</affiliation>
<affiliation dbid="15">
<name>Mike </name>
</affiliation>
</committee>
<committee committeetype="Associate">
<affiliation dbid="11">
<name>Eve </name>
</affiliation>
<affiliation dbid="12">
<name>Dan </name>
</affiliation>
<affiliation dbid="13">
<name>Harold </name>
</affiliation>
<affiliation dbid="14">
<name>Chris </name>
</affiliation>
</committee>
<committee committeetype="Associate">
<affiliation dbid="25">
<name>Malcolm </name>
</affiliation>
<affiliation dbid="15">
<name>Mike </name>
</affiliation>
</committee>