Re: Hierarchical query
Date: Wed, 13 Jun 2007 19:08:58 -0000
Message-ID: <1181761738.926537.110030_at_j4g2000prf.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