[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] build group of elements


Subject: Re: [xsl] build group of elements
From: henry human <henry_human@xxxxxxxx>
Date: Fri, 22 Jun 2012 14:53:22 +0100 (BST)

Thank you! your script gets the output I am looking for!
Now in other place
three is similar node which is more complecated and I could not use your
template to create the desired output!
Here is a sample. In this sample each
group have 3 elements and the 
name of elemnts are more complex dann befrore:
<fooGroup>
        <frirst_elment>
			<1st_elment></1st_elment>
<_2nd_element>aa</_2nd_element>
			<_3rd_element>aa</_3rd_element>
</frirst_element>
      <_2nd_elment>
			<1st_elment></1st_elment>
<_2nd_element>aa</_2nd_element>
			<_3rd_element>aa</_3rd_element>
</_2nd_element>
        <3rd_elment>
			<1st_elment></1st_elment>
<_2nd_element>aa</_2nd_element>
			<_3rd_element>aa</_3rd_element>
</3rd_element>		
</fooGroup>


hh







 

--- Martin Honnen
<Martin.Honnen@xxxxxx> schrieb am Fr, 22.6.2012:

> Von: Martin Honnen
<Martin.Honnen@xxxxxx>
> Betreff: Re: [xsl] build group of elements
> An:
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Datum: Freitag, 22. Juni, 2012 15:16 Uhr
>
henry human wrote:
> > The input file was just a sample to show the xml data
>
has more foo elements.
> > <myxmlfile>
> >
>
<ss></ss>...<foo></foo>.................<foo></foo>
> </myxmlfile>
> >
//presume there are 100 foo elements in the xml file
> > My sample output
which is created througth  xslt
> >   has groups of foo elment. Each group
>
consists of three foo elements.
> >   (each three foo elments build a
>
group). example
> >   <fooGroup>= foo[1], foo[2].
> foo[3]
> >   <fooGroup>=
foo[4], foo[5].
> foo[6]
> >   <fooGroup>= foo[7], foo[8].
> foo[9]
> 
> Do
you use XSLT 2.0 or 1.0? With 2.0 you could do e.g.
>   <xsl:param name="size"
select="3"/>
> 
>   <xsl:template match="xmlfile">
>     <xsl:for-each-group
select="foo"
> group-by="(position() - 1) idiv $size">
>       <fooGroup>
>  
      <xsl:apply-templates
> select="current-group()"/>
>       </fooGroup>
>
    </xsl:for-each-group>
>   </xsl:template>
> 
>   <xsl:template
match="foo">
>     <xsl:element name="foo{position()}">
>        <xsl:copy-of
> select="node()"/>
>     </xsl:template>
>   </xsl:template>
> 
> 
> 
> 
> --
>     Martin Honnen --- MVP Data Platform
> Development
>    
http://msmvps.com/blogs/martin_honnen/
> 
> 
> 
>
--~------------------------------------------------------------------
>
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To
unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail:
<mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --~--


Current Thread
Keywords