Jez Higgins

Freelance software grandad
software created
extended or repaired


Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations

Hire me
Contact

Older posts are available in the archive or through tags.

Feed

Arabica: When is an XPath expression not an XPath expression?

When it's an XSLT pattern, that's when.

As an XPath

    para[@ref]
selects, for a given node, its child para elements which have ref attributes. As an XSLT pattern it tests whether a given node is a para element which has a ref attribute.

Similarly, something like

    chapter/para
tests whether a given node is a para element with a chapter element parent.

In XPath terms, you'd express it as something like boolean(self::para[parent::chapter]).

Aside from this sematic difference, syntactically XSLT patterns are an XPath subset. I don't have these things evaluating yet but, thanks to the miracle that is Boost::Spirit, I've extended Arabica::XPath to parse them. Took about half an hour, including writing a pile of test cases and getting them passing. It really is a top piece of work. While it's not hard to find people rambling on about how Python or Lisp or whatever really is the thing for writing little domain specific languages, this kind of thing really shows just how deadly cool template metaprogramming can be. Read the EBNF, transcribe it into code, compile, and go. Easy, expressive and type-safe. What more could you want?


Tagged code, arabica, xml, and c++


Jez Higgins

Freelance software grandad
software created
extended or repaired

Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations

Hire me
Contact

Older posts are available in the archive or through tags.

Feed