Counting self axes

R

rob.guitar.rob

Hi,

This may be a stupid question, but if you count a self axe will it
always return 1?

For example:

count(self::*)

and

count(../../this_path/overhere/self::*)

Any help would be much appreciated. My XSL transformation is doing a
couple of strange things and I am not 100% sure on this. (plus it be
more efficient to put + 1 when required!)

Thanks, Rob.
 
J

Joris Gillis

Hi,
Tempore 20:28:59 said:
This may be a stupid question, but if you count a self axe will it
always return 1?

No, not always.
This will only return 1 if the context node is a node which has a qname: i.e. elements and processing instructions. Not all XSLT - implementations follow this though: AltovaXSLT allows attributes as well.

regards,
 
R

rob.guitar.rob

Thanks!, Rob.


Joris said:
Hi,


No, not always.
This will only return 1 if the context node is a node which has a qname: i.e. elements and processing instructions. Not all XSLT - implementations follow this though: AltovaXSLT allows attributes as well.

regards,
 
R

Richard Tobin

This may be a stupid question, but if you count a self axe will it
always return 1?

The self axis of a node always contains exactly one node (the node
itself). So count(.../self::node()) will always return 1, if "..."
selects a single node.

self::* on the other hand only matches elements, because the principal
node type for the self axis is element. So if "..." selects a single
element, count(.../self::*) will return 1. If it selects a single
node of some other type, it will return 0.

-- Richard
 
D

Dimitre Novatchev

Joris Gillis said:
Hi,
Tempore 20:28:59, die Monday 01 August 2005 AD, hinc in foro


No, not always.
This will only return 1 if the context node is a node which has a qname:
i.e. elements and processing instructions.

That's not correct.

1) self::* selects the current node only if it is an element.; not if it
is a processing instruction.

If the current node is a processing instruction, then the following
expression (using the "self" axis) selects the current node:

2) self::processing-instruction()

3) Regardless of the type of the node, it is selected by:

self::node()



Cheers,
Dimitre Novatchev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,250
Members
46,848
Latest member
Graciela Mitchell

Latest Threads

Top