w3pop.com :: ÍøÂçѧԺ :: Xquery :: XQuery FLWOR + HTML
XQuery FLWOR + HTML
::
We will use the "books.xml" document in the examples below (same XML file as in the previous chapters).
ÏÂÊö°¸ÀýÖУ¬ÎÒÃÇ»áÓõ½ "books.xml" Îĵµ£¨ÉÏÒ»ÕÂʹÓõÄXMLÎļþ£©¡£
View the "books.xml" file in your browser.
ÔÚÄãµÄä¯ÀÀÆ÷ÖÐä¯ÀÀ“books.xml”¡£
Look at the following XQuery FLWOR expression:
ÏÈ¿´¿´ÏÂÃæµÄQuery FLWOR±í´ïʽ£º
for $x in doc("books.xml")/bookstore/book/title
|
The expression above will select all the title elements under the book elements that are under the bookstore element, and return the title elements in alphabetical order.
ÉÏÊö±í´ïʽ»áÑ¡ÔñÔÚ bookstore ÔªËØÏ嵀 book ÔªËØÏÂËùÓÐ title ÔªËØ£¬²¢°´×Öĸ˳ÐòÅÅÁÐ title ÔªËØºóÊä³ö¡£
Now we want to list all the book-titles in our bookstore in an HTML list. We add <ul> and <li> tags to the FLWOR expression:
ÏÖÔÚ£¬ÎÒÃÇÏ£ÍûÔÚ HTMLÁбíÖÐÁгö bookstore µÄËùÓÐbook-titlesÔªËØ£¬Òò´Ë£¬ÎÒÃÇÐèÒªÔÚ FLWOR ±í´ïʽÖмÓÈë<ul>ºÍ<li>±êÇ©£º
<ul> |
The result of the above will be:
ÉÏÊöµÄ½á¹ûÏÔʾÈçÏ£º
<ul> |
Now we want to eliminate the title element, and show only the data inside the title element:
ÏÖÔÚ£¬ÎÒÃÇÒª³ýÈ¥ title ÔªËØ£¬Ö»ÏÔʾ title ÔªËØÀïµÄÊý¾Ý£º
<ul> |
The result will be (an HTML list):
½á¹û£¨Ò»·ÝHTMLÁÐ±í£©ÏÔʾÈçÏ£º
<ul> |
ÆÀÂÛ (0)
All