XPATH Predicate Syntax question

Discussion in 'XML' started by Sabba, May 9, 2006.

  1. Sabba

    Sabba Guest

    TESTRESULTS
    PRE
    STUDENT
    @sID=1
    @Score=5
    STUDENT
    @sID=2
    @Score=2
    STUDENT
    @sID=3
    @Score=2
    POST
    STUDENT
    @sID=1
    @Score=2
    STUDENT
    @sID=2
    @Score=5
    STUDENT
    @sID=3
    @Score=5
    SORTCRITERIA
    SORT
    @GroupID=1
    STUDENT
    @sID=1
    STUDENT2
    @sID=2
    SORT
    @GroupID=2
    STUDENT
    @sID=3


    For each
    SORTCRITERIA/SORT
    I want a sum of
    TESTRESULTS/POST/STUDENT[@sID=current()/STUDENT/@sID]/@Score
    minus
    TESTRESULTS/PRE/STUDENT[@sID=current()/STUDENT/@sID]/@Score
    BUT ONLY WHEN
    A students POST score is greater than their PRE score. In other words,
    I want to ignore changes that weren't positive. The structure is so
    that I can define (dynamically) how to group students (school, grade,
    gender, etc...) seperate from the students data that needs to be
    crunched. This allows me to add grouping criteria in one place and the
    report adapts (obviously there's more to the actual data, but it's not
    relevant here).

    Below is the closest I can come, but it requires a syntax that I don't
    think is valid, a predicate in a predicate (scope issues). I'm hoping
    someone can help me find a solution that can be implemented in a single
    XPATH statement. $SORTELEMENT contains a SORT element as seen above
    (I'm doing a for-each SORTCRITERIA/SORT). I ignored the
    SectionSummary/Ba above because they exist only once in this dataset.
    For the first SORTCRITERIA/SORT, the sum would be 3 (not 0), the 2nd
    SORT would be 3.

    Thanx in advance.

    What I have so far (please don't flame, I know how bad it looks)....

    round(((sum(/ROOT/POST/SectionSummary/Ba/St[@StudentID =
    $SORTELEMENT//STUDENT/@StudentID]/Sec/@ScaledScore[../@ScaledScore >
    /ROOT/PRE/SectionSummary/Ba/St[@StudentID =
    $SORTELEMENT//STUDENT/@StudentID]/Sec/@ScaledScore] -
    /ROOT/PRE/SectionSummary/Ba/St[@StudentID =
    $SORTELEMENT//STUDENT/@StudentID]/Sec/@ScaledScore[../@ScaledScore <
    /ROOT/POST/SectionSummary/Ba/St[@StudentID =
    $SORTELEMENT//STUDENT/@StudentID]/Sec/@ScaledScore] ) div
    count(/ROOT/POST/SectionSummary/Ba/St[@StudentID =
    $SORTELEMENT//STUDENT/@StudentID]/Sec/@ScaledScore) ) ) * 10 ) div 10
    Sabba, May 9, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    475
    Martin Honnen
    Feb 24, 2007
  2. Duncan Smith
    Replies:
    7
    Views:
    485
    Joseph Kesselman
    Mar 22, 2007
  3. Ziphims

    XPath predicate problem

    Ziphims, Jan 11, 2008, in forum: XML
    Replies:
    6
    Views:
    1,776
    P. Lepin
    Jan 12, 2008
  4. Wabiloo
    Replies:
    1
    Views:
    827
    Martin Honnen
    Jan 25, 2008
  5. Phantom
    Replies:
    5
    Views:
    763
Loading...

Share This Page