INFORMATIO
xquerynotes_2.pdf

Xml elementname searchvalue 63 xquery contents

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

saxon:evaluate(concat(’doc("catalog.xml")//’, $elementName,’[. = "’,$searchValue,’"]’)) 63 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 64 XQuery – Adding Elements and Attributes to Results – 32
Image of page 16

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

Including Elements and Attributes in Results A query may return elements and attributes from the input document Query for $prod in doc("catalog.xml")/catalog/product[@dept = ’ACC’] return $prod Results <product dept="ACC"> <number>563</number> <name language="en">Floppy Sun Hat</name> </product> <product dept="ACC"> <number>443</number> <name language="en">Deluxe Travel Bag</name> </product> There are two ways to create new elements and attributes Direct constructors : use an XML-like syntax, create elements and attributes with fixed names Computed constructors : create names that are generated dynamically 65 Direct Element Constructors Specify XML elements and attributes using XML-like syntax Use enclosed expresions : expression between { and } Query <html> <h1>Product Catalog</h1> <ul>{ for $prod in doc("catalog.xml")/catalog/product return <li>number: {data($prod/number)}, name: {data($prod/name)}</li> }</ul> </html> Results <html> <h1>Product Catalog</h1> <ul> <li>number: 557, name: Fleece Pullover</li> <li>number: 563, name: Floppy Sun Hat</li> <li>number: 443, name: Deluxe Travel Bag</li> <li>number: 784, name: Cotton Dress Shirt</li> </ul> </html> 66 XQuery – Adding Elements and Attributes to Results – 33 Enclosed Expressions (1) May evaluate to elements Query for $prod in doc("catalog.xml")/catalog/product return <li>number: {$prod/number}</li> Results <li>number: <number>557</number></li> <li>number: <number>563</number></li> <li>number: <number>443</number></li> <li>number: <number>784</number></li> May evaluate to attributes Query for $prod in doc("catalog.xml")/catalog/product return <li>{$prod/@dept}number: {$prod/number}</li> Results <li dept="WMN">number: <number>557</number></li> <li dept="ACC">number: <number>563</number></li> <li dept="ACC">number: <number>443</number></li> <li dept="MEN">number: <number>784</number></li> 67 Enclosed Expressions (2) If expression evaluates to one or more atomic values, these values are cast to xs:string and included as character data content of the element Adjacent atomic values are separated by a space <li>{"x", "y", "z"}</li> returns <li>x y z</li> with spaces To avoid this, three separate expressions can be used: <li>{"x"}{"y"}{"z"}</li> May include more than one subexpression Query for $prod in doc("catalog.xml")/catalog/product return <li>{$prod/@dept,"string",5+3,$prod/number}</li> Results <li dept="WMN">string 8<number>557</number></li> <li dept="ACC">string 8<number>563</number></li> <li dept="ACC">string 8<number>443</number></li> <li dept="MEN">string 8<number>784</number></li> 68 XQuery – Adding Elements and Attributes to Results – 34
Image of page 17
Specifying Attributes Directly Query <html> <h1 class="itemHdr">Product Catalog</h1> <ul>{ for $prod in doc("catalog.xml")/catalog/product return <li dep="{$prod/@dept}">number: {data($prod/number)}, name: {data($prod/name)}</li> }</ul> </html> Results <html>
Image of page 18

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

Image of page 19
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