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

Re: [xsl] build group of elements


Subject: Re: [xsl] build group of elements
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 24 Jun 2012 15:09:51 -0300

At 2012-06-24 17:54 +0100, henry human wrote:
Ken, unfortunatelly the elments in the output has different prefixes such as:

<_1st_
<_2nd_
<_3rd_
The names must contain the above prefixes
Your script builds only :
<_1_elment
<_1_elment
<_2_elment
<_3_elment

Why do you say this? Did you not look at the results I added to my post? I gave you my evidence that the correct result is obtained with my stylesheet ... look below again and you will see that what you want is produced using a conforming XSLT 2 processor (in my case I always use Saxon).


Maybe you get incorrect results on your machine, but it works as you wish on mine. If you aren't getting what I'm getting, then I suggest your processor is not supporting the XSLT 2 ordinal= attribute for <xsl:number/>.

. . . . . . . . Ken

--- G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx> schrieb am So, 24.6.2012:

> Von: G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx>
> Betreff: Re: [xsl] build group of elements
> An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx, xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Datum: Sonntag, 24. Juni, 2012 17:11 Uhr
> At 2012-06-24 15:41 +0100, henry
> human wrote:
> > sorry for my mistake..again the input xml data and the
> expecting output:
> > The xml data has many foo elements (1000).
>
> Just by conjecture, I'm guessing you want <fooGroup>
> to be three groups of three.  You don't explain the
> criteria, but that is the only "meaningful" interpretation I
> can see.  Next time it would help if you could explain
> your requirements when including an example rather than make
> us guess by looking at your example.
>
> If I've guessed correctly, this is done easiest with
> adjacent grouping.
>
> I hope this helps.
>
> . . . . . . . . . Ken
>
> ~/t/ftemp $ cat henry.xml
> <?xml version="1.0" encoding="UTF-8"?>
>  <xmldata>
>  <ss> s </ss>
>  <nn>n </nn>
>   <foo>tt</foo>
>    <foo>bb</foo>
>    <foo>aa</foo>
>     <foo>mm</foo>
>        <foo>ll</foo>
>        <foo>nn</foo>
>         <foo>ff</foo>
>
>    <foo>gg</foo>
>       <foo>ii</foo>
>   <hh>h</hh>
>  </xmldata>
> ~/t/ftemp $ xslt2 henry.xml henry.xsl
> <?xml version="1.0" encoding="UTF-8"?>
> <fooGroup>
>    <_1st_element>
>
> <_1st_element>tt</_1st_element>
>
> <_2nd_element>bb</_2nd_element>
>
> <_3rd_element>aa</_3rd_element>
>    </_1st_element>
>    <_2nd_element>
>
> <_1st_element>mm</_1st_element>
>
> <_2nd_element>ll</_2nd_element>
>
> <_3rd_element>nn</_3rd_element>
>    </_2nd_element>
>    <_3rd_element>
>
> <_1st_element>ff</_1st_element>
>
> <_2nd_element>gg</_2nd_element>
>
> <_3rd_element>ii</_3rd_element>
>    </_3rd_element>
> </fooGroup>~/t/ftemp $
> ~/t/ftemp $ cat henry.xsl
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:h="urn:X-henry" exclude-result-prefixes="h"
>   version="2.0">
>
> <xsl:output indent="yes"/>
>
> <xsl:template match="xmldata">
>   <xsl:for-each-group select="foo"
>
>       group-adjacent="(position()-1) idiv
> 9">
>     <fooGroup>
>       <xsl:for-each-group
> select="current-group()"
>
>
> group-adjacent="(position()-1) idiv 3">
>         <xsl:element
> name="_{h:ord(position())}_element">
>           <xsl:for-each
> select="current-group()">
>             <xsl:element
> name="_{h:ord(position())}_element">
>
> <xsl:copy-of select="node()"/>
>
> </xsl:element>
>           </xsl:for-each>
>         </xsl:element>
>       </xsl:for-each-group>
>     </fooGroup>
>   </xsl:for-each-group>
> </xsl:template>
>
> <xsl:function name="h:ord">
>   <xsl:param name="pos"/>
>   <xsl:number value="$pos" ordinal="1"/>
> </xsl:function>
>
> </xsl:stylesheet>
> ~/t/ftemp $


--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


Current Thread
Keywords