Simple XQuery FLWOR Expressions

The simplest XQuery FLWOR expression might be something like this:


              for $v in $doc//video return $v
               

            

This returns all of the video elements in $doc.

We can add a bit of substance by adding XQuery where and return clauses:


              for $v in $doc//video
               

              where $v/year = 1999
               

              return $v/title
               

            

This returns all of the titles of videos released in 1999.

If you know SQL, that XQuery probably looks reassuringly similar to the equivalent SQL statement:


              SELECT v.title 
               

              FROM video v 
               

              WHERE v.year = 1999
               

            

And if you know XPath, you might be wondering why our XQuery cannot be written as this:


              $doc//video[year=1999]/title
               

            

Well, you can. This XPath expression is completely equivalent to the FLWOR expression above, and furthermore, it is a legal XQuery query. In fact, every legal XPath expression is also legal in XQuery. Thus the first query in this section can be written as:


              $doc//video
               

            

Which style you prefer seems to depend on where you are coming from: if you have been using XML for years, especially XML with a deep hierarchy as found in "narrative" documents, then you will probably be comfortable with path expressions. But if you are more used to thinking of your data as representing a table, then the FLWOR style might suit you better.

As you will see, FLWOR expressions are a lot more powerful than path expressions when it comes to doing joins. But for simple queries, the capabilities overlap and you have a choice. Although it might be true that in SQL every query is a SELECT statement, it is not so that in XQuery every query has to be a FLWOR expression.

Translating XML documents to EDIFACT

In-place, via XSLT and via XQuery are all mechanisms supported for converting XML to EDIFACT

EDI to XML

Using the DataDirect XML Converters EDI repository, the EDI to XML Conversion module is able to support dozens of EDI standard dialects and message types like EDIFACT, HL7, and X12.

Stylus Studio is a Real Cost-Saver in Novell Implementations

Learn how TriVir, a leading consulting group used Stylus Studio to implement a Novell based solutions using DirXML, eDirectory, and the exteNd suite for their government customers.

Business Solutions & Outsourcing

Business Solutions & Outsourcing companies know the best solutions. That's why they choose Stylus Studio to enhance their business productivity. See which companies are already using Stylus Studio 2006 to take care of their own business!

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member