Xquery
XQuery is a functional language designed to query and manipulate XML data
Xslt
XSLT is a transformation language for XML designed to transform structured documents into other formats (such as XML, HTML, and plain text, or, in XSLT 3, JSON)
Class problems xml
Example |
---|
"As dimitre says xslt is much better at this class of problem than xquery" from question XQuery that selects node but omits returning child nodes "I hate to answer a request for a solution in language a by suggesting a solution in language b but what you are doing here falls into the class of problems which xslt handles much better than xquery" from question Xquery order by two variables not working |
"Saxon-ee supports streaming of large xml documents using xslt or xquery streaming is better supported in xslt than in xquery" from question Xml parsing with constant memory usage |
"But typically xslt is better for transforming xml into different xml formats on disk;xquery is better for more complex xml queries applications and when the xml is in a database" from question Choosing between LINQ, XSLT, or XQuery to process 2000 XML files |
Amenable static analysis
Example |
---|
"Xquery works better than xslt for this because it s more amenable to static analysis as it lacks the polymorphism of xslt s template rules" from question SAXON Streaming XPath in .NET |
"Xquery is more amenable to static analysis than xslt because it lacks the very dynamic template despatch mechanism" from question Determine all xpath references / xml elements "used" in an XSLT |
Others
Example |
---|
If your output is going to be similar to your input with small changes then the xslt solution is often a lot simpler than the xquery solution from question XPath/XQuery - Selecting a node while excluding some elements |
Xquery can produce a modified copy of your document but it s not particularly easy because you need to explicitly copy all the parts that you don t want to change;xslt is a better bet for producing a modified copy of the document from question How to add string content in xml nodes(empty node/append to existing content) using XPath Query |
Xslt is significantly more appropriate to use than xquery for such kind of tasks from question XQuery update question |
Xslt 2.0 and xquery 1.0 utilize xpath 2.0 which is what you are recognizing as xquery in the code above;the above code is xslt 2.0 not xquery from question Saxon CE and XQuery? Documentation indicates no XQuery, Examples otherwise? |
Unless you are using the static typing feature xquery is no more strongly typed than xslt from question Why would I choose XSLT or XQuery over the other for html document generation? This kind of processing is most easily done with xslt which is more expressive than xquery from question Eliminate a single element type from XML using XQUERY |
As for creating a sequence of attributes you can t do that in xpath which can t create new nodes you can however do that in xslt then you can use it elsewhere as in and will get xquery has a more compact syntax and in contrast to xpath allows expressions to create new nodes from question Xslt2: sequence of attribute nodes |
My usual rule-of-thumb is that xquery is better than xslt for simple tasks whereas xslt is better for complex tasks from question The ways to transform a source xml to another xml Generally i know it sounds banal xslt is better at transformation generating a new document from each source document while xquery is better at query extracting a small amount of information from each source document from question Analysing (tens of) thousands of XML files As for whether to use xslt or xquery the proof is in the pudding xslt is better at transforms and xquery is better at queries from question Why would I choose XSLT or XQuery over the other for html document generation? |
Setting a namespace as the default namespace might be useful though sadly in xquery this also makes a namespace the default namespace for the output - xslt does this better from question Possible to process XHTML with Saxon? |