Attribute keyword attribute myattr proddept is

Info icon This preview shows pages 19–21. Sign up to view the full content.

attribute keyword attribute myattr { $prod/@dept } is equivalent to attribute {concat("my", "attr")} { $prod/@dept } Computed attribute constructors can be used in direct element constructors <result>{attribute {concat("my", "attr")} { "xyz" } }</result> returns <result myattr="xyz"/> 74 XQuery – Adding Elements and Attributes to Results – 37 Turning Content to Markup Create a product catalog that has the names of the departments as element names instead of attribute values Query for $dept in distinct-values(doc("catalog.xml")/catalog/product/@dept) return element {$dept} {doc("catalog.xml")/catalog/product[@dept = $dept]/name} Results <WMN> <name language="en">Fleece Pullover</name> </WMN> <ACC> <name language="en">Floppy Sun Hat</name> <name language="en">Deluxe Travel Bag</name> </ACC> <MEN> <name language="en">Cotton Dress Shirt</name> </MEN> 75 XQuery: Contents Introduction to XQuery XQuery Foundations XQuery Expressions Navigating Input Documents Using Paths Adding Elements and Attributes to Results Selecting and Joining Using FLWORs Sorting and Grouping Functions Updates 76 XQuery – Selecting and Joining Using FLWORs – 38
Image of page 19

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

FLWOR Expressions Path expressions used to select elements from input documents FLWOR expressions allow to join data from multiple sources, construct new elements and attributes, evaluate functions on intermediate values, sort results The following query for $prod in doc("catalog.xml")//product let $prodDept := $prod/@dept where $prodDept = "ACC" or $prodDept = "WMN" return $prod/name is equivalent to the path expression doc("catalog.xml")//product[@dept = "ACC" or @dept = "WMN"]/name There can be multiple for and let clauses, in any order, followed by an optional where clause, an optional order by clause, and the required return clause A FLWOR must have at least one for or let clause FLWORs can appear in other expressions max(for $prod in doc("catalog.xml")//product return xs:integer($prod/number)) 77 The for Clause Sets up an iteration that evaluates the rest of the FLWOR multiple times, once for each item in the sequence returned by the expression after the in keyword This binding sequence can evaluate to any sequence of zero, one or more items Can be a sequence of elements, atomic values, nodes of any kind, or a mixture of items If the binding sequence is the empty sequence, the rest of the FLWOR is not evaluated (it iterates zero times) 78 XQuery – Selecting and Joining Using FLWORs – 39 Range Expressions Create a sequence of integers specifying the number of times to iterate Query for $i in 1 to 3 return <oneEval>{$i}</oneEval> Results <oneEval>1</oneEval> <oneEval>2</oneEval> <oneEval>3</oneEval> Can be included within parenthesized expressions, as in (1 to 3, 6, 8 to 10) Can use variables, as in 1 to $prodCount If the first integer is greater than the second, as in 3 to 1 , or if either operand is the empty sequence, the expression evaluates to the empty sequence for $i in 1 to count($seq) works even if $seq is an empty sequence for $i in reverse(1 to 3) allows to descend in value
Image of page 20
Image of page 21
This is the end of the preview. Sign up to access the rest of the document.
  • Winter '15
  • MAhmoudali

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern