xsl-list
[Top] [All Lists]

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

2013-05-13 22:44:51
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(_at_)CraneSoftwrights(_dot_)com 
|
Google+ profile: https://plus.google.com/116832879756988317389/about |
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal |


--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>