This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Counting Nodes


> 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...
>
> Is the following expression legal?
> count(//|//@*)
> It is supposed to count all nodes and attributes from the
> current context node.

No, it's not legal, because "//" by itself is not legal. You probably want
count(//node() | //@*) (though your phrase "nodes and attributes" is rather
confusing, as attributes are themselves nodes).

> I've noticed that different processers handle it differently, the main
> stumbling block being the "//" by itself.

Every conformant processor should reject this expression.
>
> 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).
>
An AbbreviatedRelativeLocationPath consists of a RelativeLocationPath
followed by "//" followed by a Step, so I can't see how you infer from this
that "//" can be used as an expression on its own.

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]