xsl-list
[Top] [All Lists]

Re: [xsl] Editing XPath expressions (Was: Replacing = with == and ===)

2014-08-03 04:30:11
On 3 Aug 2014, at 04:10, "Michael Kay mike(_at_)saxonica(_dot_)com" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Yes, parsing XPath expressions into some XML representation is a fairly 
specialized requirement but it arises often enough that it would be nice to 
have a generic off-the-shelf solution to it. John Lumley, for example, is 
doing it in the streamability analysis tool that he's presenting at Balisage 
next week, and Phil Fearon does it in his Saxon-CE-based editor.

A good starting point for such things is the Rex parser from Gunther 
Rademacher, which is a superb piece of technology that unfortunately suffers 
from very poor documentation and packaging.

I used REx to generate a parser for XPath (3) from the EBNF, with the target 
language being XSLT of course, and configuring REx to create code that will 
generate the parse tree. You'll get some very deep trees indeed, all the way 
down from <XPath>, so a simple collapsing process, something like

         xsl:template match="*[count(*)=1]"
             xsl:apply-templates select="*"

will give you more manageable trees. Other cases of collapsing (e.g. dropping 
tokens, coalescing axes into AxisStep) are pretty simple. [I'm not on my 
programming machine at present so can't check the details precisely, but once 
you've got the hang of it, it isn't difficult.]

I agree with Mike that an off-the-shelf solution would be helpful - perhaps a 
nice example for an XSLT3.0 xsl:package?

John Lumley
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>