Knowee
Questions
Features
Study Tools

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

Question

let moderatetreks:=//walks/trek[difficulty=moderate]letmoderate_treks := //walks/trek[difficulty='moderate'] let longest_length := max(moderatetreks/length)formoderate_treks/length) for trek in moderatetrekswheremoderate_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

🧐 Not the exact question you are looking for?Go ask a question

Solution

The error message you're seeing is because the XQuery engine is trying to convert the text value of the <length> element to a double precision floating point number, but it's failing because the text value includes non-numeric characters (in this case, "km").

To fix this, you need to extract only the numeric part of the text value before trying to convert it to a double. Here's how you can do it:

let $moderate_treks := //walks/trek[difficulty='moderate']
let $longest_length := max($moderate_treks/length/number(substring-before(., 'km')))
for $trek in $moderate_treks
where number(substring-before($trek/length, 'km')) = $longest_length
return 
    <trek name="{$trek/@name}">
        <rating>{$trek/rating/text()}</rating>
    </trek>

In this revised version of your XQuery, the substring-before(., 'km') function is used to extract the part of the text value of the <length> element that precedes the "km" string. This will be a string that consists only of numeric characters, which can then be safely converted to a double using the number() function.

This problem has been solved

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

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.

To declare a constant MAX_LENGTH with value 99.98 inside a method , you write:Group of answer choicesfinal MAX_LENGTH = 99.98;final float MAX_LENGTH = 99.98;double MAX_LENGTH = 99.98;final double MAX_LENGTH = 99.98;

<?xml version = "1.0”?> <walks> <trek name = "Kepler"> <location>Fiordland</location> <difficulty>moderate</difficulty> <length>60km</length> <rating>88</rating> </trek> <trek name = "Routeburn"> <location>Fiordland</location> <difficulty>moderate</difficulty> <length>32km</length> <rating>98</rating> </trek> <trek name = "Togariro"> <location>Togariro</location> <difficulty>hard</difficulty> <length>19.4km</length> <rating>96</rating> </trek> <walks>Write down the following English language queries in XQuery, and show the result of evaluating the XQuery query on the given XML document. (a) 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.

<?xml version = "1.0”?> <walks> <trek name = "Kepler"> <location>Fiordland</location> <difficulty>moderate</difficulty> <length>60km</length> <rating>88</rating> </trek> <trek name = "Routeburn"> <location>Fiordland</location> <difficulty>moderate</difficulty> <length>32km</length> <rating>98</rating> </trek> <trek name = "Togariro"> <location>Togariro</location> <difficulty>hard</difficulty> <length>19.4km</length> <rating>96</rating> </trek> <walks>所选文本: 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.

1/1

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.