[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to specify document order location path for id

Subject: Re: How to specify document order location path for identical elements with different parents?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 02 Apr 2004 14:53:34 -0500
mastering xpath
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[@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@xxxxxxxxxxxxxxxx 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 ======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.