Subject: Re: [xsl] Count of template matches From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 4 Nov 2014 15:01:35 -0000 |
This can easily and universally be done in a two-pass transformation. The second pass performs the counting. Cheers, Dimitre On Tue, Nov 4, 2014 at 5:58 AM, Wolfgang Laun wolfgang.laun@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Michael: > I don't think that I overlooked using position() within template, as > triggered in the apply-templates mode. But as position() is > context-dependent, it will not return the same value as when applied within > a for-each over a summarily constructed sequence of nodes. The requirement > is (cf. that other thread started yesterday) to enumerate certain nodes > across the entire document. > > -W > > On 4 November 2014 12:49, Michael Kay mike@xxxxxxxxxxxx > <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: >> >> Are you missing the fact that position() can be used during >> apply-templates processing, in the same way as during for-each processing? >> >> Michael Kay >> Saxonica >> mike@xxxxxxxxxxxx >> +44 (0) 118 946 5893 >> >> >> >> >> On 4 Nov 2014, at 11:28, Wolfgang Laun wolfgang.laun@xxxxxxxxx >> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: >> >> A recent post has asked for a way to produce ordinals for the processing >> of a set of certain nodes. >> >> If you construct a sequence of the required nodes and iterate it (using >> for-each), position() yields the ordinals. >> >> If you use template/apply-templates. you can still determine the offset by >> calling index-of. But this has a catch, since index-of still requires the >> construction of the overall sequence using an XPath expression. But (and >> this is, for me, the catch) that the selection of the nodes that will >> eventually be processed depends on attribute values of template+@match >> and/or apply-templates+@select. This means that you need two ways to produce >> the same sequence of nodes for index-of to work. (I do know that XPath is >> powerful enough. so it's not an issue of not being able to - it's just >> duplicating an effort.) >> >> A function like fn:nth-time-around() in the context of a template would >> take care of the problem, which (apparently) isn't frequent enough to >> warrant such a function. >> >> Perhaps I'm simply ignorant of something? >> -W >> >> XSL-List info and archive >> EasyUnsubscribe (by email) >> >> >> XSL-List info and archive >> EasyUnsubscribe (by email) > > > XSL-List info and archive > EasyUnsubscribe (by email)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Count of template matches, Wolfgang Laun wolfga | Thread | [xsl] Which XPath evaluates faster:, Costello, Roger L. c |
Re: [xsl] Which XPath evaluates fas, Michael Kay mike@xxx | Date | Re: [xsl] Which XPath evaluates fas, Wolfgang Laun wolfga |
Month |