This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: grouping in XPATH with parenthesis
- From: "G. Ken Holman" <gkholman at CraneSoftwrights dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 08 Jul 2002 16:05:21 -0400
- Subject: Re: [xsl] grouping in XPATH with parenthesis
- References: <200207081823.OAA02888@biglist.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
At 2002-07-08 11:49 -0700, Dan Diebolt wrote:
I recently saw an XPATH expression (in Dave Obasanjo's "Things to
Know and Avoid When Querying XML Documents") that included parentheses
used for grouping:
I wouldn't use the word "grouping" but rather "for containing a location
path expression". Sometimes, as in Dan's example, this is important in
order to distinguish what would be construed as a location step expression
to be a location path expression:
(//*)[position()=1]/@on-loan
In the above "//*" is a location path expression because of the parens.
Consider taking out the parens:
//*[position()=1]/@on-loan
This time the predicate is considered part of the second step "*" so as to
address the on-load attribute of the first element child at every child
level of the document tree.
Note that you cannot be fast and loose with parens, as addressing in a
location step is proximity ordered while the addressing in a location path
is document ordered, such that
preceding-sibling::*[1] (proximity order; addresses closest)
and
(preceding-sibling::*)[1] (document order; addresses furthest)
do not address the same node if there is more than one preceding
sibling. This is because the parens make the location step into a location
path.
I have found parens very useful when starting off a location path
expression with a union:
(a | b | c)/d/e
Remember that in a multiple step location path, parens can only be used in
the first step.
I had to scratch my head wondering if I have ever seen parentheses
used in this fashion. Is anyone familiar enough with this usage
Since day one of my XSLT/XPath training course I've underscored this with
students because it helps to understand the nuances between location steps
and paths and how proximity order differs from document order.
to explain when parenthesis would be needed and where in the
specs they are even allowed?
Production 15 in XPath.
I hope this helps.
................ Ken
--
Upcoming: 3-days XSLT/XPath and/or 2-days XSL-FO:Sep 30-Oct 4,2002
G. Ken Holman mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6 Definitive XSLT and XPath
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1 Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books (electronic, printed),
articles, training (instructor-live,Internet-live,web/CD,licensed)
Next public training: 2002-08-05,26,27,09-30,10-03
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list