RE: Position of a Child
At 03:27 PM 9/20/01, you wrote:
The problem with the solution you gave me is that this code is inside a template (that matches the contextNode), and this template calls itself recursively for a set of selected attributes.
It sounds from this that the (count(*[name()=$NodeName]/preceding-sibling::*) + 1) solution would be best. This works on the assumptions that:
- by "position" you mean to count among elements (i.e. there's no mixed-content type stuff with text nodes you have to worry about), and
- you'll never have more than one of a given node, as in
<ContextNode> <Child1/> <Child3/> <Child4/> <Child3/> <ContextNode>
Here, if $NodeName were 'Child3' and you did (count(*[name()=$NodeName]/preceding-sibling::*) + 1) you'd get 5, which isn't what you want. If you know you'll never have more than one Child3, on
<ContextNode> <Child1/> <Child4/> <Child3/> <ContextNode>
you'd get 3, which is correct.
position() is less useful to you because you have to change context and establish the correct node list in order to be able to use it -- and from what you describe, this could be too busy. (You still might try the other solution though: you might be surprised.)
To get deeper into this, if the count() solution isn't good enough, maybe you could try explaining what your recursive template call on ContextNode is actually doing: maybe there's a more efficient way to get at the problem this is solving, which would alleviate the other problem as well. But I think it should work pretty well for you.
If it doesn't, maybe a two-pass solution, marking each element with its position in pass one, would break the problem down usefully?
Hoping that helps, Wendell
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format