XQuery Ìí¼ÓÔªËØºÍÊôÐÔ

XML ʵÀýÎĵµ

ÎÒÃǽ«ÔÚÏÂÃæµÄÀý×ÓÖмÌÐøÊ¹ÓÃÕâ¸ö "books.xml" Îĵµ£¨ºÍÉÏÃæµÄÕ½ÚËùʹÓÃµÄ XML ÎļþÏàͬ£©¡£

ÔÚÄúµÄä¯ÀÀÆ÷Öв鿴 "books.xml" Îļþ¡£

Ïò½á¹ûÌí¼ÓÔªËØºÍÊôÐÔ

ÕýÈçÔÚÇ°ÃæÒ»½Ú¿´µ½µÄ£¬ÎÒÃÇ¿ÉÒÔÔÚ½á¹ûÖÐÒýÓÃÊäÈëÎļþÖеÄÔªËØºÍÊôÐÔ£º

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

ÉÏÃæµÄ XQuery ±í´ïʽ»áÔÚ½á¹ûÖÐÒýÓà title ÔªËØºÍ lang ÊôÐÔ£¬¾ÍÏñÕâÑù£º

<title lang="en">Everyday Italian</title>
<title lang="en">Harry Potter</title>
<title lang="en">Learning XML</title>
<title lang="en">XQuery Kick Start</title>

ÒÔÉÏ XQuery ±í´ïʽ·µ»Ø title ÔªËØµÄ·½Ê½ºÍËüÃÇÔÚÊäÈëÎĵµÖб»ÃèÊöµÄ·½Ê½µÄÏàͬµÄ¡£

ÏÖÔÚÎÒÃÇÒªÏò½á¹ûÌí¼ÓÎÒÃÇ×Ô¼ºµÄÔªËØºÍÊôÐÔ£¡

Ìí¼Ó HTML ÔªËØºÍÎı¾

ÏÖÔÚ£¬ÎÒÃÇÒªÏò½á¹ûÌí¼Ó HTML ÔªËØ¡£ÎÒÃÇ»á°Ñ½á¹û·ÅÔÚÒ»¸ö HTML ÁбíÖУº

<html>
<body>

<h1>Bookstore</h1>

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

</body>
</html>

ÒÔÉÏ XQuery ±í´ïʽ»áÉú³ÉÏÂÃæµÄ½á¹û£º

<html>
<body>

<h1>Bookstore</h1>

<ul>
<li>Everyday Italian. Category: COOKING</li>
<li>Harry Potter. Category: CHILDREN</li>
<li>Learning XML. Category: WEB</li>
<li>XQuery Kick Start. Category: WEB</li>
</ul>

</body>
</html>

Ïò HTML ÔªËØÌí¼ÓÊôÐÔ

½ÓÏÂÀ´£¬ÎÒÃÇÒª°Ñ category ÊôÐÔ×÷Ϊ HTML ÁбíÖÐµÄ class ÊôÐÔÀ´Ê¹Óãº

<html>
<body>

<h1>Bookstore</h1>

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

</body>
</html>

ÉÏÃæµÄ XQuery ±í´ïʽ¿ÉÉú³ÉÒÔϽá¹û£º

<html>
<body>

<h1>Bookstore</h1>

<ul>
<li class="COOKING">Everyday Italian</li>
<li class="CHILDREN">Harry Potter</li>
<li class="WEB">Learning XML</li>
<li class="WEB">XQuery Kick Start</li>
</ul>

</body>
</html>
VUE