xsl-list
[Top] [All Lists]

RE: How to specify document order location path for identical elements with different parents?

2004-04-02 13:29:39
 

-----Original Message-----
From: Alan Stein [mailto:as(_at_)medcosm(_dot_)com] 
Sent: 02 April 2004 19:38
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How to specify document order location path 
for identical elements with different parents?

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.)

count(report[(.//code[(_at_)type="a" or @type="b")][last()][(_at_)type="a"]])


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.)

count(report[(.//code[(_at_)type="a" or @type="b")][last()][(_at_)type="b"]])

Not tested.

Michael Kay