More on the XSLT/XQuery Thread

Volume 7, Issue 90; 28 May 2004; last modified 08 Oct 2010

A few more thoughts on the debate over XSLT and XQuery. You really want to do document transformations with XQuery, do you?

Dare responded a couple of days ago to my essay about XSLT and XQuery.

There were two aspects of his response that left a distinctly puzzled, nay baffled, look on my face:

  1. Per Bothner wrote an article over a year ago on about Generating XML and HTML using XQuery showing how you could use XQuery to transform an XML document to another XML format or HTML.”

  2. “XSLT is actually very bad at dealing with XML that isn't regular and has lots of mixed content”

Evan Lenz followed-up on the second point in comments directly on Dare’s essay and I won’t repeat them here. To a certain extent, it depends on what you mean by “dealing with” and the dialog between Evan and Dare exposes that pretty clearly.

The idea of using XQuery to transform DocBook is, uhm, interesting.

If you think this is a reasonable alternative to XSLT’s template-based approach:

define function convert-node ($x) {
  typeswitch ($x)
    case element article return <html>{convert-children($x)}</html>
    case element artheader return convert-artheader($x)
    case element title return <title>{convert-children($x)}</title>
    case element authorgroup return convert-children($x)
    case element author return convert-children($x)
    case element abstract return
     <div type='abstract'><h3>Abstract</h3>{convert-children($x)}</div>
    case element para return <p>{convert-children($x)}</p>
    case element screenshot return
      <img src="{string($x/mediaobject/imageobject/imagedata[@format="PNG"]/@fileref)}" />
    case element caption return <p><b>{convert-children($x)}</b></p>
    case element emphasis return <em>{convert-children($x)}</em>
    case element citation return ('[',convert-children($x),']')
    case element quote return ('"',convert-children($x),'"')
    case element classname return <code>{convert-children($x)}</code>
    case element function return <code>{convert-children($x)}</code>
    case element itemizedlist return <ul>{convert-children($x)}</ul>
    case element listitem return <li>{convert-children($x)}</li>
    case element sect1 return <div class="sect1">{convert-div-children($x, 2)}</div>
    case element sect2 return <div class="sect2">{convert-div-children($x, 3)}</div>
    case element programlisting return <pre>{convert-children($x)}</pre>
    case element informalfigure return convert-children($x)
    case element bibliography return
      <div class="bibliography"><h2>Bibliography</h2>{convert-children($x)}</div>
    case element biblioentry return <p>{convert-biblioentry($x)}</p>
    case element firstname return convert-children($x)
    case element surname return convert-children($x)
    default return ($x)

I can only say (1) I think you’re nuts and (2) I stand by my challenge: you implement all of the functionality of the DocBook Open Repository’s XSLT stylesheets in XQuery and I’ll buy you dinner at your favorite restaurant. (Mental health care you’re going to have to take care of on your own.)


But can you convert an RSS 2.0 pubDate (RFC 822) to a dc:date (W3CDTF) with it?

(An argument Dare used against SW technologies that still has me baffled...)

btw, I'm not convinced the following is such a clean alternative, but you can always do recursion without the X :

—Posted by Danny Ayers on 28 May 2004 @ 10:14 UTC #