At 02:37 PM 4/2/2004, you wrote:
1) What is the number of reports which are coded with either an "a" or
"b" where the last "a" or "b" code of the report (in document order) is an "a"?
(correct number is 3. Yes, this has been double checked.)
XPath typically provides several ways to skin any particular cat. But
count(/reportlist/report
[codelist/code/@type='a' or codelist/code/@type='b']
[descendant::code[(_at_)type='a' or @type='b'][last()]/@type='a'])
will do this.
2) What is the number of reports which are coded with either an "a" or
"b" where the last "a" or "b" code of the report (in document order) is a "b".
This looks the same as above, except that final equality test is @type='b'
not @type='a'.
In my previous posting I recevied several helpful responses.
Unfortunate that I couldn't apply them to my application because my
example was too simplified. Specifically, codes in the same report may
have different codelist parents, and this seems to be what's at the root
of my problem formulating an xpath statement.
It is also possible to write expressions for cases even more general. As
always, the trick is in getting the spec right.
Once you do that, if you know XPath, it isn't hard. Experience teaching
XSLT suggests that a thorough and more-or-less formal introduction to XPath
goes a very long way. "Faking it" proves to be false economy, as the time
you saved learning it is more than overtaken by time spend guessing and
pulling hair. So take a course that gives due attention to mastering XPath
(my company offers one :-), or take the time to work through a decent
introduction to the subject.
For completeness, I can also offer you the long version of the first of these:
count(/child::reportlist/child::report
[child::codelist/child::code/attribute::type='a' or
child::codelist/child::code/attribute::type='b']
[descendant::code[attribute::type='a' or attribute::type='b']
[position() = last()]/attribute::type='a'])
Cheers,
Wendell
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================