views:

109

answers:

3

Which one of them do you use in your applications in order to transform XML data to other data types? WHY?

+1  A: 

It depends what type of "transformation" you need, XQuery allows you to perform queries on your XML data, a bit like SQL.

XSLT allows you to apply a style on XML, like CSS does with HTML.

Romain Deveaud
I totally disagree with the statement "XSLT allows you to apply a style on XML, like CSS does with HTML.". XSLT is not to XML what CSS is to HTML. CSS tells a processor how to display the HTML. XSLT is used to transform the data into something else. You can use XSLT to transform XML to HTML so that a processor knows how the data should be displayed, but how the processor displays the resulting HTML has nothing to do with XSLT.
DevNull
A: 

If you look at the Wikipedia Entry they have a section that compares the two.

In my view I see XSLT as a Programmable presentation layer for data.

Darknight
+2  A: 

While XQuery can be used for simple transformations, it lacks the power and sofistication of XSLT (especially templates and the <xsl:apply-templates> instruction).

XSLT is a language that was especially designed to process tree structures. It is still best at doing this.

In cases when accessing an XML database it would be a good decision to use (the efficiency of) XQuery to extract the necessary XML nodes and then do the transformation with XSLT from here on. Some XSLT 2.x / XQuery processors do allow this (via extensions) even now. The next wave of XSLT 2.x/XQuery 1.x specifications will most probably make such interoperability an official feature of these languages.

Dimitre Novatchev