![]() |
xsl: how to count nodes that match a pattern
Hi,
I'm trying to use <xsl:number> to generate a sequence number of all nodes that match a particular pattern, e.g: <xsl:template match="foo"> <xsl:copy> <xsl:attribute name="id"><xsl:number level="any"/></xsl:attribute> </xsl:copy> </xsl:template> this will consecutively number all the <foo> nodes in a document. regardless of where they appear. However, in my case I have a second pattern: <xsl:template match="foo[@type='bar']" priority="1"> </xsl:template> Now, nodes that match the second template are included when generating the number for the first template, so the numbering within the output document is no longer consecutive. I realise that in this trivial case I could have used [@type <> 'bar'] to explicitly exclude some nodes from the numbering but I'm trying to figure out if there is a simple way to just say 'count all nodes that are processed by this pattern' (like if I was using an imperative language I would just increment a variable every time I output the id attribute) TIA Andy |
Re: xsl: how to count nodes that match a pattern
but I'm trying to figure out if there is a simple way to just say 'count all nodes that are processed by this pattern' No. (like if I was using an imperative language I would just increment a variable every time I output the id attribute) that would be (potentially) a different number again of course, counting how many times the template is executed would also count any executions that generate nodes into a variable rather into the final result tree. David |
Re: xsl: how to count nodes that match a pattern
Am Mon, 14 Feb 2005 14:20:06 GMT schrieb David Carlisle:
> but I'm trying to figure > out if there is a simple way to just say 'count all nodes that are processed > by this pattern' > > No. > is there non-simple but general way, meaning a pure XSLT 1.0 solution using parameterized templates, but no XSLT extensions? I'm not sure this question is sufficiently precise to admit of a precise answer ... [Smullyan] -- Sebastian |
Re: xsl: how to count nodes that match a pattern
Sebastian Millies <REPLACE-OBVIOUSsDOTmilliesATidsMINUSscheerDOTde> writes:
> Am Mon, 14 Feb 2005 14:20:06 GMT schrieb David Carlisle: > > > but I'm trying to figure > > out if there is a simple way to just say 'count all nodes that are processed > > by this pattern' > > > > No. > > > is there non-simple but general way, meaning a > pure XSLT 1.0 solution using parameterized templates, > but no XSLT extensions? I think you'd have to say No to that as well. Given an existing stylesheet the way to answer the question about how often a particular template is run would be to use some external tracing or profiling tool. Eg if you are using saxon the output of saxon -T would tell you that soon enough. > > I'm not sure this question is sufficiently precise > to admit of a precise answer ... [Smullyan] > > -- Sebastian David |
| All times are GMT. The time now is 11:08 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.