Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: xpath



On Apr 5, 10:03pm, Peter Stephenson wrote:
} Subject: Re: xpath
}
} On Fri, 04 Apr 2008 09:01:22 -0700
} Jack Bates <ms419@xxxxxxxxxxxxxx> wrote:
} > I have a content repository mounted on my filesystem. Attributes are
} > mapped to filesystem extended attributes. I want to use XPath
} > expressions like: /myrepo/subdir/*[@user.repository_id = a16]
} 
} Just to be clear: do you need *exactly* xpath syntax, as given above?

That's not a very representative sample of xpath syntax.  Inside the
[ ] can be an arbitrarily complex expression, with parentheses for
grouping, function calls with their argument lists in parentheses,
logical operators, etc.  (If you enjoy attempting to make sense of
impenetrable descriptive prose, try <http://www.w3.org/TR/xpath>.
It can't be any harder than, say, understanding Sven's C code in the
completion modules.)

} If so, then the answer is no: this conflicts with ordinary shell syntax
} where [...] specifies a character class and since any set of characters
} can appear within it there's no way of interpreting it any other way.

It's worse than that, isn't it?  Spaces inside the [ ] would cause the
parts of the pattern to be interpreted as separate words.  Anyway, the
application of the predicate inside the [ ] is dependent on the syntax
of the path that precedes it; it's applied as a filter, quite like zsh's
(e[...]) glob qualifier, really.

} Or are you happy with something that looks a bit like xpath syntax, and
} can be converted (possibly automatically) into it?  If the latter, we
} could probably come up with something using shell functions and glob
} qualifiers.

Indeed, given an external program that interprets the predicate syntax,
I think it'd be fairly easy to write something with (e) to apply it.
It'd look something like

/myrepo/subdir/*(e{'reply=($(xpred $REPLY "[@user.repository_id = a16]"))'})

assuming xpred takes a filename and a predicate and outputs the list of
whatever it is from the file.



Messages sorted by: Reverse Date, Date, Thread, Author