INFORMATIO
xquerynotes_2.pdf

A sequence of xsstring values that are substrings of

Info icon This preview shows pages 14–16. Sign up to view the full content.

: a sequence of xs:string values that are substrings of product names Only the last step in a path may return atomic values rather than nodes An error is raised if a step that is not the last returns atomic values, as in product/substring(name,1,30)/replace(.,’ ’,’-’) 56 XQuery – Navigating Input Documents Using Paths – 28
Image of page 14

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

Predicates in Path Expressions Used to filter the results to contain only nodes that meet specific criteria Select elements that have a certain value for an attribute or child element: product[@dept = "ACC"] , product[number < 500] Select elements that have a particular attribute or child element: product[@dept] , product[color] , Select elements that occur in a particular position within their parent: product[3] product[number] 6 = product/number 3 both expressions filter out products that have no number child 3 return the product or the number element, respectively Effective Boolean value of the expression is determined If it is true for a particular node, that node is returned, otherwise the node is not returned 57 Comparisons in Predicates Value comparison operators only allow a single value General comparison operators allow sequences of zero, one, or more values //priceList[@effDate eq ’2006-11-15’] is acceptable each priceList element can have only one effDate //priceList[prod/@num eq 557] will raise an error prod/@num returns more than one value per priceList //priceList[prod/@num = 557] returns a priceList if it has at least one prod child whose num attribute is equal to 557 3 If a priceList does not have any prod children with num attributes, it does not return that priceList , but it does not raise an error Value comparison operators treat untyped data like strings //priceList/prod[@num eq 557] raises an error if no schema is present Using = , the value of the attribute will be casted to xs:integer and then com- pared to 557 58 XQuery – Navigating Input Documents Using Paths – 29 Positional Predicates Specify the position of an item within the sequence of items being processed Numbering starts at 1 doc("catalog.xml")/catalog/product[4] : The fourth product in the catalog May be a predicate expression that evaluates to an integer If the number is greater than the number of items in the context sequence, it does not raise an error; it does not return any nodes doc("catalog.xml")/catalog/product[99] returns the empty sequence Specifies the position within the current sequence of items being processed, not the position of an element relative to its parent’s children doc("catalog.xml")/catalog/product/name[1] : first name child of each prod- uct (doc("catalog.xml")/catalog/product/name)[1] : first name element in doc- ument 59 The position and last functions position function: Takes no argument, returns an integer representing the po- sition (starting with 1, not 0) of the context item doc("catalog.xml")/catalog/product[position() < 3] : first two product children of catalog doc("catalog.xml")/catalog/product/*[position() < 3]
Image of page 15
Image of page 16
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