Thank you for the feedback. I agree it is both very cool and it could be further improved: it could recognize more patterns similar to XSLT match patterns, like "qq/*/zz", "qq//zz" or "qq[zz]" etc.
However, certain things already work: the pattern is relative to the end, not from the beginning of the abs path, which would need to start with "/" to be required. Although the pattern-matching part resembles XSLT match, which is natural, the right-hand side is from another area, in particular, parser construction--mostly inspired by Coco/R, a cute little compiler generator for LL(k) grammars. (Although x2j does not describe a grammar nor is it attributed--it is only the right-hand side that is similar.) In other words, it is an instance of blending the declarative nature of pattern matching and mapping thereof into procedural code processing with some notion of state. In response to "CSV -> XML" discussion, it occurred that the ideas of x2j could be taken further--by replacing the procedural part with a mapping to J pseudo-XML structures. http://www.jsoftware.com/pipermail/programming/2009-November/016871.html I came up with the ideas of bidirectional x2j, as I was watching the sunset from the hills of Berkley over the Golden Gate bridge. http://www.timeanddate.com/worldclock/astronomy.html?n=224&month=11&year=2009&obj=sun&afl=-11&day=1 So you can see how certain vistas can be very inspiring. (Where other "Vistas" can be very UN-inspiring.) I am still waiting for a follow up on "CSV -> XML"... > From: Dan Bron <[email protected]> > > I had played with xml/sax before, but I'd never seen xml/sax/x2j: > > http://www.jsoftware.com/jwiki/Addons/xml/sax/x2j%20Examples > > For others who haven't seen it, it's a compact, declarative syntax for > addressing and transforming XML paths. Think XSLT but more concise; so it > preserves the joy of J programming while providing flexibility to work > with XML (which is not an easy interface to design; J likes rectangles, > not trees). > > In combination with web/httpget (another gift from my wishlist) and > regexes, J finally has the tools to express concise, precise web data > transformation. For an example, see the "Sort most popular programming > languages" task on RC: > > http://rosettacode.org/wiki/Sort_most_popular_programming_languages#J > > and the linked notes on the Talk page. > > In the past to accomplish this sort of task, I would go through a lengthy > process using several external tools: wget (fetch) > tidy (force HTML into > XHTML) > xsltproc (address interesting data) > J (transform data). But I > won't do that anymore. In particular I won't miss XSLT, which I never got > a hang of, and was always the longest and most laborious part of the > process [1]. > > -Dan > > [1] Of course, XSLT still has some advantages over x2j, which is built on > SAX. In particular, XSLT has a full implementation of XPath, but SAX is > limited to static, literal paths (basically because it passes you every > node and lets you decide if you're interested in it; and the x2j is simply > a more productive syntax/interface over this mechanism, which simply > compares the path of the current node to the paths you've registered > interest in). > > However, I do see one potential improvement that x2j does have control > over, to wit, the need for assignment in order to build tables > (rectangles) of interest. I understand why this is neccesary in the > general case (and why it's easy to implement, given SAX's callback > nature). But I'd be interested in discussing an extension. > > I envision syntacic sugar that bypassed the need for assignment and > permitted a functional description of transforming paths and sub-paths > into tables (functional at the notational level anyway, which is all > that's important). Combined with the existing compact format this > extension would allow x2j to embody the best principles of J, seamlessly > extending its reach to XML and other tree structures. > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
