ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: Xquery :: XQuery FLWOR + HTML

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

Xquery
XQuery ½éÉÜ
XQuery ʵÀý
XQuery FLWOR ±í´..
XQuery FLWOR + H..
XQuery ÊõÓï
XQuery Óï·¨
XQuery Ìí¼ÓÔªËØº..
XQuery Ñ¡ÔñºÍ¹ýÂ..
XQuery º¯Êý
XQuery ÕªÒª
XQuery ²Î¿¼

XQuery FLWOR + HTML


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ÐÞ¸Ä:2007-08-22 ä¯ÀÀ:2008 :: ::

The XML Example Document
XML °¸ÀýÎĵµ

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”¡£


Present the Result In an HTML List
ÔÚHTMLÁбíÖÐÏÔʾ½á¹û

Look at the following XQuery FLWOR expression:
ÏÈ¿´¿´ÏÂÃæµÄQuery FLWOR±í´ïʽ£º

for $x in doc("books.xml")/bookstore/book/title
order by $x
return $x

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>
{

for $x in doc("books.xml")/bookstore/book/title
order by $x
return <li>{$x}</li>

}
</ul>

The result of the above will be:
ÉÏÊöµÄ½á¹ûÏÔʾÈçÏ£º

<ul>
<li><title lang="en">Everyday Italian</title></li>
<li><title lang="en">Harry Potter</title></li>
<li><title lang="en">Learning XML</title></li>

<li><title lang="en">XQuery Kick Start</title></li>
</ul>

Now we want to eliminate the title element, and show only the data inside the title element:
ÏÖÔÚ£¬ÎÒÃÇÒª³ýÈ¥ title ÔªËØ£¬Ö»ÏÔʾ title ÔªËØÀïµÄÊý¾Ý£º

<ul>
{
for $x in doc("books.xml")/bookstore/book/title
order by $x
return <li>{data($x)}</li>

}
</ul>

The result will be (an HTML list):
½á¹û£¨Ò»·ÝHTMLÁÐ±í£©ÏÔʾÈçÏ£º

<ul>
<li>Everyday Italian</li>
<li>Harry Potter</li>
<li>Learning XML</li>
<li>XQuery Kick Start</li>

</ul>

ÆÀÂÛ (0) All