RE: [xsl] Dirty Input

Subject: RE: [xsl] Dirty Input
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 20 Jul 2006 11:48:45 +0100
Easy with 2.0:

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

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Khorasani, Houman [mailto:Houman.Khorasani@xxxxxxxxxxxx] 
> Sent: 20 July 2006 11:30
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Dirty Input
> 
> Hello,
> 
> Our system is generating some very dirty XML input. I am not 
> sure if there would be any solution to this problem at all.  
> At first it might remind you of my similar request from last 
> week. But this time the elements are not that conveniently 
> grouped into one parent tag but are rather loose.
> 
> The tag <Devices> contains elements <a>, <b> and <c> in that 
> order respectively.  The elements <b> and <c> incl. their sub 
> elements are optional and may be not in the input file. But 
> <a> is mandatory and would always be in the input file.
> 
> The output shall give the exact structure as the input file 
> but group <a>, <b> and <c> together and put a <device> tag 
> between each group.
> Since <a> is mandatory we could take it as a base and say the 
> first <a> is in the first group and the following tags until 
> the next <a> belong to group 1 as well.  The next <a> belongs 
> to group 2 and any following tags until the next <a> shall be 
> in group 2 as well, etc.  Each group shall be separated by a 
> <device> tag. Otherwise the same structure of the input file 
> shall be copied.
> 
>  Input file:
> 
> <bla>x</bla>
> <bla>x</bla>
> <Devices>
> 	<a>
> 		<a2>1</a2>
> 	</a>
> 	<b>
> 		<b2>
> 			<b3>1</b3>
> 			<b4>1</b4>
> 		</b2>
> 		<b2i>
> 			<b3i>1</b3i>
> 			<b4i>1</b4i>
> 		</b2i>
> 		...
> 	</b>
> 	<c>1</c>
> 	<a>
> 		<a2>1</a2>
> 	</a>
> 	<b>
> 		<b2>
> 			<b3>1</b3>
> 			<b4>1</b4>
> 		</b2>
> 		<b2i>
> 			<b3i>1</b3i>
> 			<b4i>1</b4i>
> 		</b2i>
> 		...
> 	</b>
> 	<c>1</c>
> 	...
> </Devices>
> 
> Output:
> 
> <bla>x</bla>
> <bla>x</bla>
> <Devices>
> 	<device>
> 		<a>
> 			<a2>1</a2>
> 		</a>
> 		<b>
> 			<b2>
> 				<b3>1</b3>
> 				<b4>1</b4>
> 			</b2>
> 			<b2i>
> 				<b3i>1</b3i>
> 				<b4i>1</b4i>
> 			</b2i>
> 			...
> 		</b>
> 		<c>1</c>
> 	</device>
> 	<device>
> 		<a>
> 			<a2>1</a2>
> 		</a>
> 		<b>
> 			<b2>
> 				<b3>1</b3>
> 				<b4>1</b4>
> 			</b2>
> 			<b2i>
> 				<b3i>1</b3i>
> 				<b4i>1</b4i>
> 			</b2i>
> 			...
> 		</b>
> 		<c>1</c>
> 	</device>
> 	...
> </Devices>
> 
> 
> Do you guys think this would be possible at all?
> 
> Many Thanks,
> Houman

Current Thread