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

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: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 13 May 2013 22:44:46 -0500

At 2013-05-13 20:29 -0700, Dimitre Novatchev wrote:
So here is the complete solution to this problem, using XSLT 3.0:

Thank you, Dimitre, for taking the time to polish up the data ... I didn't have the time.


I implemented the untested code from yesterday and found that Ihe's use of the descendent:: axis was insufficient to detect differences between two siblings. That was easily corrected in the XSLT 2.0 solution below that produces the identical serialized result as yours.

I hope this helps readers of the archive.

. . . . . . . . . Ken


T:\ftemp>type ihe.xml <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>

T:\ftemp>call xslt2 ihe.xml ihe.xsl
<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>

T:\ftemp>type ihe.xsl
<xsl:stylesheet version="2.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="string-join(descendant-or-self::*/
                       concat(local-name(),'$',count(ancestor::*)),' ')">
    <group>
      <xsl:sequence select="current-group()"/>
    </group>
  </xsl:for-each-group>
 </xsl:template>
</xsl:stylesheet>

T:\ftemp>rem Done!


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