XML/XPath: Difference between revisions

Content added Content deleted
Line 368:
<lang xquery>
 
(:
(: 1. Retrieve the first "item" element :)
let $firstItem := //item[1]
Notice the braces around //item. This evaluates first all item elements and then retrieving the first one.
Whithout the braces you get the first item for every section.
:)
let $firstItem := (//item)[1]
 
(: 2. Perform an action on each "price" element (print it out) :)
Line 394 ⟶ 398:
<price>14.50</price>
<description>Makes you invisible</description>
</item>
<item upc="485672034" stock="653">
<name>Blork and Freen Instameal</name>
<price>4.95</price>
<description>A tasty meal in a tablet; just add water</description>
</item>
</firstItem>