PXSL Tools 1.0: Your ticket out of XML Hell

Posted by Tom Moertel Tue, 18 Dec 2007 03:33:00 GMT

XML is fine for representing document-like things, but when it’s twisted to represent build recipes, configuration files, and little programming languages, it opens the gates to XML Hell. Once the gates are opened, the demons of cargo-cult thinking are loosed upon the world, where they are free to trick innocent programmers into working with grotesquely twisted XML documents – something no human mind was designed to comprehend. Ensnared, these programmers are slowly drawn into the depths of XML Hell, from which their lamentations echo across the universe.

When the demons of cargo-cult thinking come for you, don’t be ensnared! Instead, be prepared – with PXSL – the Parsimonious XML Shorthand Language (pronounced “pixel”).

What’s PXSL? It’s a luxurious, thermonuclear smoking jacket that you can slip on using a convenient preprocessor. Use it whenever you see grotesque XML on the horizon. Within PXSL’s plush (and stylish) protection, you can create all the nasty, twisted XML that may be demanded of you, but you need not descend into XML Hell to do it. Instead, you can work from the comfort of a well-stocked lounge, where clarity and conciseness are always on tap.

For example, here’s a snippet from an XSLT stylesheet, in the original XML:

<xsl:template match="/">
  <xsl:for-each select="//*/@src|//*/@href">
    <xsl:value-of select="."/>
    <xsl:text>&#10;</xsl:text>
  </xsl:for-each>
</xsl:template>

And here’s the same snippet, written in PXSL:

template /
  for-each //*/@src|//*/@href
    value-of .
    text <<&#10;>>

Isn’t that refreshing?

Why PXSL?

There are lots of XML shorthands available. (The PXSL FAQ lists about ten of them.) So why choose PXSL? Here’s why:

Also, PXSL is battle tested. It was first released in 2003 and has been saving people from XML Hell since. People who try it seem to like it:

  • I think PXSL could do wonders for soothing my irrational hatred for all things XML.kowey
  • Impressive… I converted some of my files from XML to PXSL and the readability was much improved.chris
  • Quite aside from the fact that XSLT is finally somewhat readable, the fact that you’ve added a serious macro system means that some serious scripting of XML can occur. I’m very impressed.invisible

The next time you’re headed for XML Hell, why not give the venerable PXSL a try? You might just find that you like it, too.


This public service announcement was brought to you in celebration of the 1.0 release of the pxsl-tools package. The PXSL-to-XML compiler pxslcc is written in Haskell and uses the cross-platform Haskell Cabal build/package system to let you use PXSL just about anywhere.

Posted in
Tags , , ,
13 comments
no trackbacks
Reddit Delicious

Comments

  1. Kristian said 5 days later:

    That’s very nice and all (and I remember you espousing PSXL before on HuSi), but what if one isn’t running Haskell? Any idea how har it would be to wrap this for, say, Python?

  2. Tom Moertel said 5 days later:

    Kristian, the PXSL-to-XML preprocessor is written in Haskell, but the result is a stand-alone binary – you don’t need to learn (or use) Haskell to use it. If you’re running Fedora Linux, for example, you can just install one of the pxsl-tools RPMs I’ve packaged, and you’ll be ready to roll. Other folks have contributed binaries for Windows and Mac OS X, but they are a bit out of date. (Contributions of more-recent versions are welcome.)

  3. Cory von Wallenstein said 20 days later:

    Thanks to your tip that I picked up last week, I’ve found myself requiring my XML validator probably about a quarter as often as I required when I was buried deep in XML Hell. Thanks!

  4. defel said 48 days later:

    Many thanks for PXSL .. I am using XML and XSL for years, and waited always for something like pxsl, great utility! :)

  5. Quark said 122 days later:

    1.0! Lovely :). I’ve been a PXSL user for years now. PXSL is a really nice language and a really elegant design.

    I use it for all web pages I generate from XML, and these days I use it for a fair number of configuration files too (e.g. for OPML for bookmarks).

    Thanks for the lovely tool Tom.

  6. Tom Moertel said 124 days later:

    Thanks for the kind words, Quark! You made my day.   :-)

  7. hdh said 195 days later:

    Hi, is there an emacs mode for PXSL? I see the PXSL page has “mode: outline” at the end, but I don’t see any use for it when editing PXSL.

  8. Tom Moertel said 195 days later:

    hdh, there is not a PXSL mode for Emacs, as far as I know.

    Writing one would be an interesting exercise. A simple PXSL mode, supporting only PXSL syntax, would be straightforward to implement. A more advanced PXSL mode, offering XML editing features within PXSL’s XML fragments (you can embedd XML in PXSL documents), would be a much more difficult project.

    If you (or anybody) is interested in writing a PXSL mode, I would be happy to add it to the official PXSL distribution. ;-)

    Cheers,
    Tom

  9. Krzysztof Nosek said 597 days later:

    I tried to use PXSL in my production environment, but all the time I’m getting stuck against the same problem: I think it lacks the feature of defining optional attributes for macros (I suppose, perhaps because there’s no conditional facility in PXSL to test their presence).

    I tried to hack out some limited solution, but unfortunately, the lack of Haskell experience makes all my efforts ineffective. But maybe it needs no hacking at all? Is there a way to pass optional attributes in current-state PXSL macro system?

  10. Tom Moertel said 597 days later:

    @Krzysztof Nosek: You are right: PXSL does not support optional macro parameters. Depending on what you need, however, there may be other means of getting it done. Can you be more specific about your actual problem?

  11. Krzysztof Nosek said 598 days later:

    Hi Tom, thank you for your interest in my problem.

    Well, in the XML subset I work with, there is an element Phase, which can optionally take the attribute @objective. These elements are used in many ways which follow a single pattern, so I’ve decided to create a simple macro language. A simplified example:

    
    ,goto target distance =
      Phase -type=<<go to>> -distance=<(,distance)>
        ,dest -object=<(,target)>
    
    

    What now if I wated my macro to take optional attribute, like this:

    
    ,goto target distance objective =
      Phase -type=<<go to>> -distance=<(,distance)> -objective=<(,objective)>
        ,dest -object=<(,target)>
    
    

    But how would I check if it’s set? Or perhaps how would I extend PXSL, assuming that all parameters declared after some &optional keyword are to be passed directly down, similar to ,BODY, but serialized as attributes, not elements? (that’s how I’d do “optional” child element)

    I think I can guess the source of my troubles: my XML is too attribute-oriented. Were all that stuff modelled with elements, I think PSXL would easily crunch them. But that language was given to me as such, sorry.

    Would be nice to hear some comments, as I’m desperate enough to consider a switch to some Lisp dialect…

  12. Tom Moertel said 601 days later:

    @Krzysztof Nosek: Unfortunately, you are right: PXSL doesn’t give you a way to expand a macro into attributes, so you can’t do what you want directly. You can, however, create variants of your macros for the different sets of parameters you expect, e.g.:

    ,goto2 target distance =
      Phase -type=<<go to>> -distance=<(,distance)>
        ,dest -object=<(,target)>
    
    ,goto3 target distance objective =
      Phase -type=<<go to>> -distance=<(,distance)> -objective=<(,objective)>
        ,dest -object=<(,target)>
    

    But that solution is practical only if your macros are simple and the combinations of optional parameters are few. If your macros are more complex, you can use anonymous functions to factor the non-varying portions into a common macro:

    ,goto target distance mk-phase =
      ,mk-phase -type=<<go to>> -distance=<(,distance)>
        dest -object=<(,target)>
    
    ,goto2 target distance =
      ,goto target distance <(
        , type distance =
          Phase -type=<<go to>> -distance=<(,distance)>
            ,BODY  )>
    
    ,goto3 target distance objective =
      ,goto target distance <(
        , type distance =
          Phase -type=<<go to>> -distance=<(,distance)> -objective=objective
            ,BODY  )>
    

    Still, if the combinations of optional parameters are more than a few, this workaround gets old fast.

    Cheers,
    Tom

  13. Krzysztof Nosek said 602 days later:

    Tom,

    I noticed that 1) PXSL compiler doesn’t report an error when a macro is not supplied with all parameters, and 2) such an undefined parameter evaluates to "(UNDEFINED)". Guess what? I allow my users to pass arguments optionally, and I post-process resulting XML with sed/perl/xslt/whatever to get rid of any attributes in the form attrib="(UNDEFINED)". I wonder how wrong it is, but still, works for me. :)

Trackbacks

Use the following link to trackback from your own site:
http://blog.moertel.com/articles/trackback/672

(leave url/email »)

   Comment Markup Help Preview comment