Ancestor or self the context node and all its

Info icon This preview shows pages 13–15. Sign up to view the full content.

ancestor-or-self:: The context node and all its ancestors preceding:: All nodes that precede the context node in the document, minus the context node’s ancestors preceding-sibling:: All the siblings of the context node that precede it 3 Attributes of the same element are not considered siblings 51 Node Tests Each axis step has a node test that indicates which of the nodes to select, along the specified axis Two kinds of node tests: by name or by node kind Node name tests : tests based on names, such as product and dept Node kind tests 3 node(): retrieve all different kinds of nodes (child element, text, comment, and processing-instruction nodes) but not attributes Different from * , which selects child element nodes only 3 ancestor::node() returns all ancestor element nodes and the document node (if it exists) Different from ancestor::* , which returns ancestor element nodes only 3 attribute::node() return attribute nodes (means the same as @* ) 3 Four other kind tests: text() , comment() , processing-instruction() , and documentnode() 52 XQuery – Navigating Input Documents Using Paths – 26
Image of page 13

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

Node Name Tests and Namespaces Names used in node tests are qualified names ( QName ) they are affected by namespace declarations A namespace declaration is in scope if it appears in an outer element, or in the query prolog If a name is prefixed, its prefix must be mapped to a namespace using a names- pace declaration If an element name is unprefixed, and there is an in-scope default namespace de- clared, it is considered to be in that namespace; otherwise, it is in no namespace Attribute names are not affected by default namespace declarations 53 Node Name Tests and Namespaces: Example Input document ( prod_ns.xml ) <prod:product xmlns:prod=" "> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> Query declare namespace prod = " "; <prod:prodList>{ doc("prod_ns.xml")/prod:product/prod:number }</prod:prodList> Results <prod:prodList xmlns:prod=" "> <prod:number>563</prod:number> </prod:prodList> 54 XQuery – Navigating Input Documents Using Paths – 27 Wildcards, Abbreviations Wildcards can be used to match names child::* (abbreviated * ) selects all element children, regardless of name attribute::* , (or @* ) selects all attributes, regardless of name Wildcards can be used for just the namespace and/or local part of a name prod:* selects all child elements in the namespace mapped to the prefix prod *:product selects all product child elements that are in any namespace, or no namespace Some axes and steps can be abbreviated . self::node() .. parent::node() @ attribute:: // /descendant-or-self::node()/ 55 Expressions as Steps Expressions can be used as tests 3 product/(number | name) : all number and name elements 3 product/(* except number) : all children of product except number 3 product/ (if (desc) then desc else name) : for each product element, the desc child if it exists; otherwise, the name child 3 product/substring(name,1,30)
Image of page 14
Image of page 15
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