CenturionStudio.it - Fotolia

Problem solve Get help with specific problems with your technologies, process and projects.

XQuery examples

Data services expert, Larry Fulton, gives a general overview of when to use XQuery and when to use XSLT.

Do you have any examples for when I should use XQuery and for when XQuery won't be able to meet my XML needs?

Some specific examples of what you need to do with XML would probably make it easier to provide an exact answer, but here is a general overview. You may be able to do everything you need with XQuery, and you should recognize that XQuery overlaps functionally with eXtensible Stylesheet Language Transformations (XSLT). Both languages include XPath syntax and structures. The best answer to your question is that there are places where XSLT is a stronger choice, for example if you want to make small changes to a document (for example, if you wanted to delete or modify every instance of a particular element type). Another example is writing code intended for use in different environments, where XSLT offers features that support things like dynamic binding.

XQuery is a more formal language and is probably easier to learn. In the absence of programming needs that are just not readily expressed in XQuery, you can most likely get away with XQuery.

From an architecture perspective, if you are going to use overlapping tools in an ongoing basis, my recommendation is always to establish a clear set of guidelines as to what you do with which tool, rather than letting this decision be made case-by-case based on the particular developer's skills, familiarity, or preferences. If you do let this happen on a case-by-case basis, you will in short order have a wide range of approaches in production, and this will in turn unnecessarily complicate your future maintenance efforts.

Dig Deeper on Topics Archive

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.