[xsl] Re: How to specify document order location path for identical elements with different parents?

Subject: [xsl] Re: How to specify document order location path for identical elements with different parents?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 2 Apr 2004 12:34:34 -0800 (PST)
"Alan Stein" <as@xxxxxxxxxxx> wrote in message
news:406DC109.6090406@xxxxxxxxxxxxxx
> Thanks much for the help with my previous posting. 
> 
> I think I've better articulated my question in the following example:
> 
> Given the following XML:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <reportlist>
>     <report>
>         <codelist>
>             <code type="a"/>
>         </codelist>
>         <codelist>
>             <code type="b"/>
>             <code type="c"/>
>         </codelist>
>     </report>
>     <report>
>         <codelist>
>             <code type="a"/>
>             <code type="b"/>
>         </codelist>
>         <codelist>
>             <code type="a"/>
>         </codelist>
>     </report>
>     <report>
>         <codelist>
>             <code type="z"/>
>             <code type="a"/>
>             <code type="d"/>
>         </codelist>
>     </report>
>     <report>
>         <codelist>
>             <code type="a"/>
>             <code type="e"/>
>             <code type="f"/>
>         </codelist>
>     </report>
>     <report>
>         <codelist>
>             <code type="e"/>
>         </codelist>
>     </report>
> </reportlist>
> 
> 
> How do I perform the following queries?
> 
> 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.)
> 
> 
> 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".
> 
> (correct number is 1.  Yes, this has been double-checked.)
> 
> 
> 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.  Hopefully the revised 
> example more accurately reflects my problem. 
> 
> Thanks again for the help.  I'm impressed by the brainpower in XML 
> design and available in this forum.
>        --Alan


Use:

1.

count(
/*/report/codelist[code/@type[.='a' or .='b']]
                       [last()]
                          /code[@type[.='a' or .='b']][@type='a']
      )


2.

count(
/*/report/codelist[code/@type[.='a' or .='b']]
                       [last()]
                          /code[@type[.='a' or .='b']][@type='b']
      )



Hint: I used the Xpath Visualizer for a few minutes to find this
solutions.


Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html 

__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

Current Thread