Re: [xsl] XTTE1100: A sequence of more than one item is not allowed as the @group-adjacent attribute

Subject: Re: [xsl] XTTE1100: A sequence of more than one item is not allowed as the @group-adjacent attribute
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Mon, 13 May 2013 20:29:20 -0700
So here is the complete solution to this problem, using XSLT 3.0:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/*">

  <xsl:for-each-group select="*" group-adjacent="serialize(.)">
    <group>
      <xsl:sequence select="current-group()"/>
    </group>
  </xsl:for-each-group>
 </xsl:template>
</xsl:stylesheet>

When this transformation is applied on the provided (and corrected
from severe malformities) XML document:

<A>
   <!-- start group -->
   <B>
      <C/>
      <D/>
   </B>
   <B>
      <C/>
      <D/>
   </B>
   <!-- end group -->
   <B/>  *** singleton group
   <C/>  *** singleton group
   <!-- start group -->
   <D>
     <E/>
     <E>
       <F/>
      </E>
    </D>
    <D>
     <E/>
     <E>
       <F/>
      </E>
    </D>
    <!-- end group -->
      <!-- start group -->
   <B>
      <C/>
      <D/>
   </B>
   <B>
      <C/>
      <D/>
   </B>
   <!-- end group -->
   </A>


the wanted, correct result is produced:

<group>
   <B>
      <C/>
      <D/>
   </B>
   <B>
      <C/>
      <D/>
   </B>
</group>
<group>
   <B/>
</group>
<group>
   <C/>
</group>
<group>
   <D>
     <E/>
     <E>
         <F/>
      </E>
    </D>
   <D>
     <E/>
     <E>
         <F/>
      </E>
    </D>
</group>
<group>
   <B>
      <C/>
      <D/>
   </B>
   <B>
      <C/>
      <D/>
   </B>
</group>


Cheers,
Dimitre Novatchev



On Sun, May 12, 2013 at 9:42 PM, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> serialize() is an XPath 3.0 function:
>
> http://www.w3.org/TR/xpath-functions-30/#func-serialize
>
> On Sun, May 12, 2013 at 9:08 PM, Ihe Onwuka <ihe.onwuka@xxxxxxxxx> wrote:
>> It has since occurred that the client will probably live with
>> discrepancy of the initial version. Nonetheless I am trying to look up
>> serialize. It's not an XPath 2 function is it?
>>
>> On Mon, May 13, 2013 at 4:56 AM, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
>>> Yes, this should work:
>>>
>>>     group-adjacent="*/serialize(.)"
>>>
>>> On Sun, May 12, 2013 at 8:48 PM, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
>>>> It seems to me that something like this might be useful:
>>>>
>>>> group-adjacent="my:deepEqualAdjacent(*)"
>>>>
>>>>
>>>> of course this only conveys the idea -- it is obvious that this isn't precise.
>>>>
>>>>
>>>> On Sun, May 12, 2013 at 8:08 PM, G. Ken Holman
>>>> <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
>>>>> At 2013-05-12 20:00 -0700, Dimitre Novatchev wrote:
>>>>>>
>>>>>>      select="*" group-adjacent="string-join(descendent::*/local-name(),'
>>>>>> ')"
>>>>>>
>>>>>> this treats the following two fragments as belonging to the same
>>>>>> group, and I believe Ihe doesn't want this:
>>>>>>
>>>>>>  <B>
>>>>>>      <C/>
>>>>>>      <D/>
>>>>>>   </B>
>>>>>>
>>>>>> and
>>>>>>
>>>>>>  <B>
>>>>>>      <C>
>>>>>>        <D>
>>>>>>     </C>
>>>>>>   </B>
>>>>>
>>>>>
>>>>> Well spotted, Dmitre.
>>>>>
>>>>> How about something like the following to make the distinction, using a
>>>>> simple non-name character to attach the depth to the name?
>>>>>
>>>>>   group-adjacent="string-join(descendent::*/
>>>>>                              concat(local-name(),'$',count(ancestor::*)))"
>>>>>
>>>>> (untested)
>>>>>
>>>>>
>>>>> . . . . . . . . Ken
>>
>
>
>
> --
> Cheers,
> Dimitre Novatchev
> ---------------------------------------
> Truly great madness cannot be achieved without significant intelligence.
> ---------------------------------------
> To invent, you need a good imagination and a pile of junk
> -------------------------------------
> Never fight an inanimate object
> -------------------------------------
> To avoid situations in which you might make mistakes may be the
> biggest mistake of all
> ------------------------------------
> Quality means doing it right when no one is looking.
> -------------------------------------
> You've achieved success in your field when you don't know whether what
> you're doing is work or play
> -------------------------------------
> Facts do not cease to exist because they are ignored.
> -------------------------------------
> Typing monkeys will write all Shakespeare's works in 200yrs.Will they
> write all patents, too? :)
> -------------------------------------
> I finally figured out the only reason to be alive is to enjoy it.



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread