[xsl] Complex transform + adding an incremental integer to an attribute

Subject: [xsl] Complex transform + adding an incremental integer to an attribute
From: "Mathieu Sagot" <mathieu.sagot@xxxxxxxxxxxxxxx>
Date: Wed, 22 Jun 2005 18:32:01 +0100
 Hello list,

I have been trying to create a list of nodes containing sometimes the
parent and sometimes the childs depending on a "selected" attribute (but
then not keeping the parent).
While keeping the order the nodes came from.
+ adding an "order" attribute which is an incremental integer.

Which would give:

	Input XML					->
Output XML

<n1 id=1>						-> <newNode
order=1>...</newNode>
	<n2 id=1 selected=0>...</n2>
	<n2 id=2 selected=0>...</n2>
</n1>
<n1 id=2>						-> this one is
not kept as we will keep some of the childs
	<n2 id=1 selected=1>...</n2>		-> <newNode
order=2>...</newNode>
	<n2 id=2 selected=0>...</n2>
	<n2 id=3 selected=1>...</n2>		-> <newNode
order=3>...</newNode>
</n1>
<n1 id=3>						-> <newNode
order=4>...</newNode>
	<n2 id=1 selected=0>...</n2>
	<n2 id=2 selected=0>...</n2>
</n1>


I tried to do a template select to return all the wanted nodes and then
use position() to feed the order attribute, but by using the operator |
I ended up with first all the nodes coming from n1 and then all the
nodes coming from n2, which is not the order I want them. And also the
node <n1 id=1> would be transferred although its childs are transferred.

It is a bit of a dual problem because of this order attribute, which is
incremental...

I would be happy with any clue/quidelines/ideas.
Although I am not sure if my explanations are very clear.

Anyway, I thought of a backup solution of using two xsl transform, one
to get all the nodes I want in the correct order, and an other xslt to
fill the order attribute using position()

Thank you for your time

Mathieu Sagot

Current Thread