Xquery
Published: 04:54, Tuesday 16 August 2011
Notes
What's this? See my article about Notes.
xpath:
nodename
root: /
all matching descendants: //
current: .
parent: ..
select attributes: @attr
predicates:
[pred], [1], [last()-1], [position()<3], [@lang], [@lang='eng'], [price>35.00]
wildcards:
any element: *
any attribute: @*
any node: node()
several paths: p1 | p2
axes
axisname::nodetest[predicate]
ancestor, ancestor-or-self, attribute, child, descendant, descendant-or-self, following, following-sibling, namespace, parent, preceding, preceding-sibling, self
operators:
| + - * div = != < >= > >= or and mod
select
doc("books.xml")/bookstore/book[price>30]/title
flwor:
for $x in select_query
where $x/predicate
order by $x/xpath
return $x/xpath
html:
<ul>
{
for $x in doc("books.xml")/bookstore/book/title
order by $x
return <li>{data($x)}</li>
}
</ul>
conditional statements:
for $x in doc("books.xml")/bookstore/book
return if ($x/@category="CHILDREN")
then <child>{data($x/title)}</child>
else <adult>{data($x/title)}</adult>
modify result:
add elements/add attributes:
return <li class="{data($x/@category)}">{data($x/title)}. Category: {data($x/@category)}</li>
for:
for $x in (1 to 5)
for $x at $i in doc(...
let $x := (1 to 5)
functions:
built-in
uppercase()
substring(str,start,len)
user-defined functions:
declare function prefix:function_name($parameter AS datatype)
AS returnDatatype
{
...
}
check: xlink, xpointer
Write a Comment
Name:
*
Email:
Website:
If you are human write 'a':
*
Title:
*
Your comment:
*
* These fields are mandatory.
© Copyright 2009-2011 Nicola Marcacci Rossi