Re: [xml] How could I understand the slightly difference of the parsing process of E1/E2[E3] and E1[E2][E3]?

Thank you Bruce,
My colleague began to have some approval of dealing a step (regardless of how many predicates attached) as a whole, //rec/(para[1]). That is a big progress for me.
We are following the XPath 2.0 spec. Are the both have the same behaviour about the parsing of steps with predicates?
While we still cannot reach an agreement about the DFS and BFS dispute. For example, step1/step2/step3/step4, assume that each has multiple matched nodes, should it be interpreted as step1/(step2/(step3/step4)) or ((step1/step2)/step3)/step4?
From: Bruce R Miller <bruce miller nist gov>
To: Ming Chen <ciming chen yahoo com>
Cc: "xml gnome org" <xml gnome org>; Liam R E Quin <liam holoweb net>
Sent: Friday, January 20, 2012 4:49 AM
Subject: Re: [xml] How could I understand the slightly difference of the parsing process of E1/E2[E3] and E1[E2][E3]?

Ming Chen wrote:
> Hi Experts,
> Recently a colleague and I have disagreed on the parsing process of the E1/E2[E3], where E3 has a numeric type. Here is the example XML file:
> <?xml version="1.0" encoding="UTF-8"?>
> <xml>
> <table>
> <rec id="1">
> <para type="error" position="11"/>
> <para type="warning" position="12"/>
> <para type="warning" position="13"/>
> </rec>
> <rec id="2">
> <para type="warning" position="21"/>
> <para type="warning" position="22"/>
> <para type="warning" position="23"/>
> </rec>
> <rec id="3">
> <para type="info" position="31"/>
> <para type="warning" position="32"/>
> <para type="warning" position="33"/>
> </rec>
> </table>
> </xml>
> For XPath _expression_ "//rec/para[1]", xmllint.exe outputs:
> <para type="error" position="11"/><para type="warning" position="21"/><para type="info" position="31"/>
> While my colleague said that the output should be: <para type="error" position="11"/>

Your colleague is is interpreting the xpath _expression_ as ( //rec/para ) [1]
rather than
//rec / (para[1])

See section 2.1 of the XPath (1.0) spec; The predicate,
in this case [1], is part of the "step".
So //rec selects a set of <rec> nodes, then for each, the
next step "para[1]" is applied and the union is formed.
Not that the predicate [1] is applied to the union.


> So, what's the nice distinction between E1/E2[E3] and E1[E2][E3].

The first xpath has 2 steps, where the 2nd step has one predicate.
The second xpath has 1 step which has 2 predicates.
When there are multiple predicates, they are applied
left to right as if they were successive filters.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]