Rapid Prototyping with XQuery 4

XQuery 4 is another alternative when building prototype web applications. In contrast to the XPath-like X-Query, XQuery allows complex output documents to be constructed within the query expression. Basically, XQuery combines the facilities of XPath and XSLT, but uses different syntax. Briefly, XQuery's advantages and disadvantages are as follows:

Advantages

  • XQuery combines the processing power of XPath and XSLT into one consistent language.

  • XQuery can convert XML into almost any output format, from HTML over XHTML to WML, SVG, SMIL, etc. This allows support not only for HTML clients but also for mobile clients, and for multimedia applications.

  • User-definable XQuery functions allow for modular query expressions.

  • The XML Schema type system and namespaces are fully supported.

  • XQuery 4 features easy-to-read SQL-like syntax. An alternative syntax (XQueryX) allows the formulation of queries as XML documents.

  • Processing can be embedded into the query. Extra stylesheets are not required. In contrast to W3C, XQuery 4 also supports insert, update and delete operations.

Disadvantages

  • Currently, no WYSIWYG editors exist that can produce XQuery from a web page design. The same is true for QbE (Query by Example) front-ends.

In the following example we show how we can produce a web page with XQuery 4. The example is a simplified version of the first example shown in the section Procedural Transformation.

default element namespace="http://www.softwareag.com/tamino/doc/examples/models/jazz/encyclopedia"

<html><head/><body>
    {for $a in input()/album
	return
    <table><tr><td>
      <table width="100%">
        <tr bgcolor="silver">
          <td>
            <h2>{string($a/title)}</h2><br/>
              { for $p in $a/publisher
                return
		 string-join(("Publisher:",string($p))," ")
	      }
            AlbumNo: {string($a/@albumNo)}
          </td>
          { for $c in $a/coverImage
            return
            <td>
              <img src="{string($a/coverImage)}" alt="{string($a/title)}"/>
            </td>
          }
       </tr>
      </table>
    </td></tr>
    <tr><td>
      <br/><h4>Tracks</h4>
      <table width="100%" >
	{ for $track in $a/track
          return
          <tr bgcolor="silver">
            <td>
              { string($track/title) }
            </td>
            <td align="Right">
              { $track/duration }
            </td>
          </tr>
        }
      </table>
    </td></tr>
  </table>
  }
</body></html>