Subject: Re: [xsl] Count elements A up to any element B in an axis From: Lars Huttar <lars_huttar@xxxxxxx> Date: Tue, 30 Nov 2010 10:56:08 -0600 |
On 11/30/2010 10:09 AM, Christian Roth wrote: > Hello, > > using XSLT 2. > > Effectively, I need to determine the level of a (possibly nested) list I > (=context node) am at. > > I thought I would do this by counting my ancestor list elements A. > However, certain elements along that axis establish a new level-counting > context (e.g. a table cell or a footnote, B), so I only want to count > until such an element first appears in the ancestor chain. > > My current solution is > > count( > ancestor-or-self::A[ . >> ancestor::node()[self::B or /][1] ] > ) > > Is this a correct and good way (both in being a generic enough pattern > to re-use for such problems and performance) to do it, or are there > better ways? Christian, Hopefully someone else will come along with a full recommendation, but I noticed that in your predicate [self::B or /] the '/' part will always return a non-empty sequence, so the predicate will always be true, and thus useless. You need to make the '/' part test the context node, so I believe instead of '/', you want '|self::document-node()'. I.e. | [self::B or self::document-node()] Lars
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Count elements A up to any el, Christian Roth | Thread | Re: [xsl] Count elements A up to an, David Carlisle |
[xsl] Count elements A up to any el, Christian Roth | Date | Re: [xsl] Count elements A up to an, David Carlisle |
Month |