xml - Group child nodes into group of 4 -


i have following xslt, using identity transform because need keep xml intact , change specific section of xml i.e: <committee committeetype="associate">

   <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">         <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']/affiliation">             <committee committeetype="associate">                  <xsl:copy>                       <xsl:apply-templates select="node()|@*"/>                    </xsl:copy>              </committee >       </xsl:template>    <xsl:template match="committee[@committeetype='associate']">         <xsl:apply-templates/>   </xsl:template>  </xsl:stylesheet> 

transforms

<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> 

into

            <committee committeetype="associate">                 <affiliation dbid="11">                     <name>eve </name>                 </affiliation>             </committee>             <committee committeetype="associate">                 <affiliation dbid="12">                     <name>dan </name>                 </affiliation>             </committee>             <committee committeetype="associate">                 <affiliation dbid="13">                     <name>harold </name>                 </affiliation>             </committee>             <committee committeetype="associate">                 <affiliation dbid="14">                     <name>chris </name>                 </affiliation>             </committee>             <committee committeetype="associate">                 <affiliation dbid="25">                     <name>malcolm </name>                 </affiliation>             </committee>             <committee committeetype="associate">                 <affiliation dbid="15">                     <name>mike </name>                 </affiliation>             </committee> 

how can make groups affiliation 4 per <committee committeetype="associate">

such as

  <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> 

thanks in advance.

here suggestion might suffice:

<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() &lt; $chunk-size]"/>     </committee>   </xsl:template>   </xsl:stylesheet> 

it transforms

<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> 

into

<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> 

i don't know whether committee elements have other child elements affiliation ones above stylesheet processes. if there more code needed.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -