[xsl] impossible to implement this algorithm in xslt?

Subject: [xsl] impossible to implement this algorithm in xslt?
From: "Tom Schmitter" <toms@xxxxxxxxxxxxxxxxx>
Date: Thu, 24 Jul 2008 16:29:13 -0700 (PDT)
I'm beginning to despair in the possibility that it may be impossible to
implement this algorithm in xslt. Perhaps one of you battle-hardened vets
could shed some light...
 
Input doc:
<doc>
	<sect depth="3">heading</sect>
	<A level="1">
		<B level="2">xx</B>
	</A>
	<sect depth="7">heading2</sect>
	<C level="1">
		<D level="2">yy</D>
	</C>
</doc>

Desired output:
<doc>
	<sect depth="3">heading</sect>
	<A level="4">
		<B level="5">xx</B>
	</A>
	<sect depth="7">heading2</sect>
	<C level="8">
		<D level="9">yy</D>
	</C>
</doc>

Note how the 'level' attributes in the output represent the sum of their
value in the input and the value of the 'depth' attribute of the <sect>
which precedes it.

Given the recursive processing paradigm of xslt, without the ability for a
template to return a value or to set a global variable, I can't figure out
how I can process the <sect>s and make the value of their 'depth'
attributes available for the processing of the other elements.

Would someone please tell me I'm missing something?!?

Thanks very much

Current Thread