This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Counting Nodes
- From: "Christopher R. Maden" <crism at maden dot org>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 26 Nov 2001 01:20:28 -0800
- Subject: Re: [xsl] Counting Nodes
- Reply-to: xsl-list at lists dot mulberrytech dot com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 00:46 26-11-2001, Richard Jinks wrote:
>More of an XPath question than an XSLT question, but it arose from an
>example transformation, so this seems like a good place to ask...
It is indeed.
>Is the following expression legal?
>count(//|//@*)
No.
>The reason I'm asking is that I'm currently evaluating a few different XSLT
>processers, with a view to using one of them in a product I'm working on.
>I've noticed that different processers handle it differently, the main
>stumbling block being the "//" by itself.
They should all stumble on it. Have any accepted it?
>I've tried reading the XPath spec and the XSLT Programmers Reference (2nd
>Ed), but I can't arrive at a conclusive decision.
>They appear to imply that I can't use the // by itself, needing to follow it
>with a node set (i.e. //* (which won't help, btw, as it doesn't count the
>text nodes) ), but there are sections which suggest that I can use it as a
>node set (e.g. AbbreviatedRelativeLocationPath, p354 of above book).
The implications are right. AbbreviatedRelativeLocationPath in the XPath
spec is:
RelativeLocationPath '//' Step
and neither Step may not be the null string. To count *all* of the nodes
in a document, try count(/descendant-or-self::node() | //@*). That will
count the root node itself, and all text, element, PI, comment, and
attribute nodes. If you don't want to count the root node itself, try
count(//node() | //@*).
HTH,
Chris
- --
Christopher R. Maden, Principal Consultant, HMM Consulting Int'l, Inc.
DTDs/schemas - conversion - ebooks - publishing - Web - B2B - training
<URL: http://www.hmmci.com/ > <URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4 5DFC AC52 F825 AFEC 58DA
-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.8
iQA/AwUBPAIJXKxS+CWv7FjaEQKkzwCfX+UbMpeSNp7xuBsGgTZen7HvZ5gAni4M
3kuQ1jyCnZjwdvns7EA46NPQ
=Sh+y
-----END PGP SIGNATURE-----
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list