[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 12:11:45 -0300

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"?>
 <ss> s </ss>
 <nn>n </nn>
~/t/ftemp $ xslt2 henry.xml henry.xsl
<?xml version="1.0" encoding="UTF-8"?>
</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"

<xsl:output indent="yes"/>

<xsl:template match="xmldata">
  <xsl:for-each-group select="foo"
                      group-adjacent="(position()-1) idiv 9">
      <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:function name="h:ord">
  <xsl:param name="pos"/>
  <xsl:number value="$pos" ordinal="1"/>

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