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

RE: [xsl] Constructing hierarchical XML from a flat XML-tag sequence using XSLT


Subject: RE: [xsl] Constructing hierarchical XML from a flat XML-tag sequence using XSLT
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 27 Aug 2002 16:06:20 +0100

This is a kind of grouping problem which I call "positional grouping".

In XSLT 2.0 you can do

<xsl:for-each-group select="*" group-starting-with="a">
  <a>
   <xsl:copy-of select="current-group() except ."/>
  </a>
</xsl:for-each-group>

In 1.0 my usual approach is

<xsl:for-each select="a">
  <a>
    <xsl:copy-of select="following-sibling::*
         [generate-id(preceding-sibling::a[1])=generate-id(current())]">
  </a>
</xsl:for-each>

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Lars Eskildsen
> Sent: 27 August 2002 11:35
> To: XSLT List (E-mail)
> Subject: [xsl] Constructing hierarchical XML from a flat 
> XML-tag sequence using XSLT
> 
> 
> Hello!
> 
> I want to be able to convert XML code like
> 
> <XMLCODE> 
> <a/><b/><c/><d/><a/><b/><c/><d/><a/><b/><c/><d/><a/><b/><c/><d/>
> </XMLCODE>
> 
> to the following XML:
> 
> <NEWXMLCODE>
> <a>
> 	<b/>
> 	<c/>
> 	<d/>
> </a>
> <a>
> 	<b/>
> 	<c/>
> 	<d/>
> </a>
> <a>
> 	<b/>
> 	<c/>
> 	<d/>
> </a>
> </NEWXMLCODE>
> 
> The DTD for the input XML is:	<!ELEMENT XMLCODE (a | b | c | d)+>
> 				a, b, c, d are empty tags
> 
> The DTD for the output XML is:	<!ELEMENT NEWXMLCODE (a+)>
>                                                 <!ELEMENT a 
> (b | c | d)*>
> 				b, c, d are empty tags
> 
> Can this be done? and how? 
> I just can't figure it out!
> 
> /Lars Eskildsen
> 
> 
> 
> ** Stibo Graphic          | Søren Nymarks Vej 21 | DK-8270 Højbjerg 
> ** mailto:laes@xxxxxxxxx  | http://www.stibographic.com 
> ** Phone:  +45 8939 8939  | Fax:    +45 8939 8940
> ** Direct: +45 8939 7421
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords