Let’s say I have some XSL transforming XML. Is it possible for the same XSL sheet to run a second sweep over the resultant XML? For example, let’s say my XSL turns
<xml>
<animal><dog>Rex</dog></animal>
<animal><dog>Henry</dog></animal>
<animal><dog>Fido</dog></animal>
</xml>
into
<xml>
<dog>Rex</dog>
<dog>Henry</dog>
<dog>Fido</dog>
</xml>
I don’t want to output that; rather, I then want to perform more XSL based on THAT, i.e. resultant, XML structure.
A practical example? I want to append to each dog node the number of proceeding dog siblings it has. So it would end up like:
<xml>
<dog>Rex (2)</dog>
<dog>Henry (1)</dog>
<dog>Fido (0)</dog>
</xml>
This could not be done on the first sweep because in the beginning XML, the dog nodes were not siblings – they each lived inside an animal node.
[EDIT: I know this could be done by interrogating instead the index of the parent animal node, but that’s only for this contrived example; generally, I still need to know how to act on transformed XML – if it’s even possible]
I hope that makes some sort of sense. If there is a really easy way to do this, go easy on me, as I’m no XSL ninja…
Thanks in advance
You can use modes on templates to process nodes more than one time but with different transformations. So you could do e.g.
That above is fine only with XSLT 2.0 however, with XSLT 1.0 you have the drawback that a temporary result is a result tree fragment which you need to convert into a node-set first with an extension function like exsl:node-set so with XSLT 1.0 you need e.g.