[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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

Subject: Re: [xsl] Editing XPath expressions (Was: Replacing = with == and ===)
From: "John Lumley john.lumley@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 3 Aug 2014 09:30:01 -0000

> On 3 Aug 2014, at 04:10, "Michael Kay mike@xxxxxxxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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

Current Thread