Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   xsl: how to count nodes that match a pattern (http://www.velocityreviews.com/forums/t168788-xsl-how-to-count-nodes-that-match-a-pattern.html)

Andy Fish 02-14-2005 02:00 PM

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




David Carlisle 02-14-2005 02:20 PM

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

Sebastian Millies 02-16-2005 11:58 AM

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

David Carlisle 02-16-2005 01:00 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57