Re: Hierarchical query

From: Vadim Tropashko <vadimtro_invalid_at_yahoo.com>
Date: Wed, 13 Jun 2007 12:10:15 -0700
Message-ID: <1181761815.759271.158100_at_i13g2000prf.googlegroups.com>


On Jun 13, 9:19 am, Jan Hidders <hidd..._at_gmail.com> wrote:
> Ok. I'm going to assume the following DTD (in a notation of my own
> making to make it a bit more readable) for the syntax tree. (It uses
> no attributes to keep things simple):
>
> <stat_bl> --> <decl_kw> <decl_item_list> <begin_kw> <statements>
> <semicol_kw> <end-kw>
> <decl_kw> --> EMPTY
> <begin_kw> --> EMPTY
> <end_kw> --> EMPTY
> <semicol_kw> --> EMPTY
> <statements> --> ( <stat_bl> | <assignment> )+
> <assignment> --> <var> <assign_kw> ( <var> | <number> ) <semicol_kw>
> <var> --> PCDATA
> <assign_kw> --> EMPTY
> <number> --> PCDATA
> <decl_item_list> --> ( <var> <type> <semicol_kw> )+
> <type> --> PCDATA

All right, the DTD is a bastardized [context free?] grammar describing a language that XML document is an element of. Although the adjectives "cumbersome" and "ugly" still apply, I grudgingly admit that the idea that a grammar fits into DTD effortlessly is quite powerful (so I'm removing the "XML sucks" image from my homepage:-)

> For starters I'll first do the reverse query,
> so I will assume there
> is a variable $dvar that contains a <var> element that describes a
> variable in a declaration. The XPath expression that walks to all the
> <var> nodes in an assignment that are in the scope of $dvar is as
> follows:
>
> (1) $dvar/(
> (2) ../../statements//assignment/var[string() = $dvar/string()]
> (3) minus
> (4) ../../statements//stat_bl[decl_item_list/var/string() = $dvar/
> string()]/statements//var
> (5) )
>
> The idea is quite simple: the path expression in line (2) walks to all
> variables that are nested within the statement block of the
> declaration $dvar, ...

I have trouble comprehending this line

(2) ../../statements//assignment/var[string() = $dvar/string()]

should I read it left to right? Then the ".." selects the parent of the current node, and what is the current node? Or do we start from some node that mathes "statements", then go two levels up? The statement block <stat_bl> is only one level up! Received on Wed Jun 13 2007 - 21:10:15 CEST

Original text of this message