[xsl] Dirty Input

Subject: [xsl] Dirty Input
From: "Khorasani, Houman" <Houman.Khorasani@xxxxxxxxxxxx>
Date: Thu, 20 Jul 2006 11:29:43 +0100
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