Write down the following English language queries in XQuery, and show the result of evaluating the XQuery query on the given XML document。For the longest treks among those with difficulty moderate, return an element node labelled trek with i) attribute child name that contains the name of the trek and ii) an element child labelled rating that has the text of the rating of the trek as content.
Question
Write down the following English language queries in XQuery, and show the result of evaluating the XQuery query on the given XML document。For the longest treks among those with difficulty moderate, return an element node labelled trek with i) attribute child name that contains the name of the trek and ii) an element child labelled rating that has the text of the rating of the trek as content.
Solution
I'm sorry, but you didn't provide the XML document that the XQuery should be evaluated on. However, I can provide a general XQuery that might fit your needs. Please adjust it according to your XML structure.
let $longest-trek := max(/treks/trek[difficulty='moderate']/length)
for $t in /treks/trek[difficulty='moderate' and length=$longest-trek]
return
<trek name="{$t/name}">
<rating>{$t/rating}</rating>
</trek>
This XQuery first calculates the maximum length of all moderate treks. Then it selects all treks that are moderate and have this maximum length. For each of these treks, it returns a new trek element with an attribute name containing the name of the trek and a child element rating containing the rating of the trek.
Please note that this XQuery assumes that your XML has a structure like this:
<treks>
<trek>
<name>Trek 1</name>
<difficulty>moderate</difficulty>
<length>10</length>
<rating>5</rating>
</trek>
<trek>
<name>Trek 2</name>
<difficulty>hard</difficulty>
<length>20</length>
<rating>4</rating>
</trek>
<!-- more treks -->
</treks>
If your XML structure is different, you need to adjust the XQuery accordingly.
Similar Questions
Write down the following English language queries in XQuery, and show the result of evaluating the XQuery query on the given XML document. For every distinct difficulty, return an element node difficulty with i) an attribute child called value that lists the difficulty, ii) an element child trek for every trek with that difficulty, and iii) an element child avg length that contains the average length over all of these treks.
<?xml version = "1.0” encoding = "UTF-8"? > <doc> <a> <b> <a/> <a/> </b> <b> <a/> </b> <b> <a/> <a> <b/> <b/> </a > <a/> </b> </a> </doc> ) Convert each of the following queries into the corresponding XPath expression, and evaluate it on the tree by listing the pre-identifier of the nodes returned. i. For every element child m of some element node, and for every node n that is the third among all b-labelled element children of m, return the node that is the second among all element children for some descendant-or-self node of n.
Consider the following XML document. <?xml v e r si o n = ‘ ‘1.0”? > <walks> <t r e k name= ‘ ‘ Keple r”> <l o c a ti o n >Fi o rdl and </l o c a ti o n > <d i f f i c u l t y >moderate</ d i f f i c u l t y > <len g th >60km</len g th> <r a ti n g >88</ r a ti n g > </t re k> <t r e k name= ‘ ‘ Routeburn”> <l o c a ti o n >Fi o rdl and </l o c a ti o n > <d i f f i c u l t y >moderate</ d i f f i c u l t y > <len g th >32km</len g th> <r a ti n g >98</ r a ti n g > </t re k> <t r e k name= ‘ ‘ T on g a ri r o C r o s si n g”> <l o c a ti o n >Tongariro </l o c a ti o n > <d i f f i c u l t y >hard</ d i f f i c u l t y > <len g th >19.4km</len g th> <r a ti n g >96</ r a ti n g > </t re k> <walks>For every distinct location l for which no trek with rating less than 85 exists, return an element node with label location that has the following content: i) a child element labelled location name with the name of the location as text content, and ii) for each trek in that location, an element child labelled trek with the name of the trek as text content.
let $moderate_treks := //walks/trek[difficulty='moderate'] let $longest_length := max($moderate_treks/length) for $trek in $moderate_treks where $trek/length = $longest_length return <trek name="{$trek/@name}"> <rating>{$trek/rating/text()}</rating> </trek>err:FORG0001: Cannot cast <length>60km</length> to double
Write the following English language query in regular property graph logic:Return the trek nodes that have 2 or 3 sections.Such as:(答案像以下这种格式写出来)result(y) ← :flight(x, y), x.name = “Papeete”result(y) ← :flight(x, s1), :flight(s1, y), x.name = “Papeete”result(y) ← :flight(x, s1), :flight(s1, s2), :flight(s2, y), x.name = “Papeete”
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.