[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XML-aware programming language?


computationally complete programming language
> It seems odd to me that I've never seen an article comparing 
> actual XSLT and
> XQuery code for say moderately complex operations.

Apart from my Knight's Tour, which Jonathan cited (and which is a very
untypical application), I thought I'd try a very simple transformation that
I had to do recently. The task is to remove those parts of a document rooted
at an element having the attribute secret="yes". This is bog-standard XSLT
and doesn't need any 2.0 features:

<xsl:template match="*">
<xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[@secret='yes']"/>

7 lines, of which 6 are copy-and-paste from many other stylesheets that
you've written before. (Add two lines if you will for the header and
footer).

Here's an attempt at an XQuery solution:

declare function m:copy($e as element()) as element()? {
  if ($e/@secret = 'yes')
    then ()
    else element {node-name($e)} { 
           $e/@*, 
           for $n in $e/node() return 
               if $n instance of element()
               then m:copy($n)
               else $n
    }
}

document{
  m:copy(doc('input.xml')/*)
}

14 lines of code (twice as much), and less scope for reuse. No great
difference in the conceptual difficulty - both require an understanding of
recursion - but I think XSLT emerges here as the winner. (And remember this
is only XSLT 1.0).

But in fact there's a bigger issue - the XQuery code is wrong. It loses the
namespaces from the source document. Perhaps I'm missing something, but I
can't see any way to solve this. XQuery may be computationally complete, but
it's not actually closed over the data model - there is no way of generating
a namespace dynamically. As far as I can see at the moment, that's a
stopper, and this exercise has to be coded in XSLT.

Of course, I'm sure there are other problems where XQuery has the edge.

Michael Kay
http://www.saxonica.com/
           
    


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.