[http://creativecommons.org/licenses/by/3.0/]
This work is licensed under a CC
Attribution 3.0 Unported License [http://creativecommons.org/licenses/by/3.0/]
Set Operationson Sequences
While XPath 2.0 syntactically is an extension of XPath 1.0, the underlying data model has changed quite radically. Instead of XPath 1.0's simple concept of four datatypes (node set, number, string, boolean), the XQuery 1.0 and XPath 2.0 Data Model (XDM) is based on sequences and allows much more sophisticated ways of data representation and manipulation. Furthermore, XDM includes the datatypes defined by XSD, which results in an complex and powerful collection of built-in datatypes and operations on these datatypes.
//img[not(@alt)]
count(//img)
/descendant::img[3]/@src
starts-with(/html/@lang, 'en')
Sequences replace node-sets from XPath 1.0. In XPath 1.0, node-sets do not contain duplicates. In generalizing node-sets to sequences in XPath 2.0, duplicate removal is provided by functions on node sequences.(XDM [http://www.w3.org/TR/xpath-datamodel/#sequences])
= != < <= > >=
$X = $Y
some $x in $X, $y in $Y satisfies $x eq $y
eq ne lt le gt ge
is << >>
$a is $bis true only if both variables identify the same node
generate-id($a) = generate-id($b)
$a << $bis true if $a precedes $b in document order
$X = $Xis not always true
$X != 'test'and
not($X = 'test')are not the same
$X != 'test'is true if one item in $X is not equal to 'test'
not($X = 'test')is true if no item in $X is equal to 'test'
@mode != 'test'is false if there is no @mode!
$X = $Yand
$Y = $Zdoes not imply
$X = $Z
(1, 2),
(2, 3), and
(3, 4)illustrate this behavior
partial equality(one item must be equal)
empty(()) = true()
exists((1, 2, 3)) = true()
if ( exists(@email) ) then …
if ( empty(@email) ) then …
Set Operationson Sequences
sets(no duplicates, document order)
() | ()
sets(no duplicates, document order)
() intersect ()
sets(no duplicates, document order)
() except ()
deep-equal((1, 2, 3), (1, 3, 2)) ≡ false()
((1, 2, 3), (4, 5, 6)) ≡ (1, 2, 3, 4, 5, 6)
reverse((1, 2, 3, 4)) ≡ (4, 3, 2, 1)
index-of((1, 2, 3, 1), 1) ≡ (1, 4)
subsequence((1, 2, 3, 4, 5, 6, 7), 5, 2) ≡ (5, 6)
insert-before(("one", "two", "four"), 3, "three") ≡ ("one", "two", "three", "four")
remove(("white", "white", "black", "white"), 3) ≡ ("white", "white", "white")
distinct-values((1, 2, 3, 1, 2, 6, 7)) ≡ (1, 2, 3, 6, 7)
unordered((1, 2, 3, 4, 5)) ≡ (3, 4, 1, 2, 5)
count((1, 2, 3, 4, 5, 6)) ≡ 6
avg((1, 2, 3, 4, 5, 6)) ≡ 3.5
max($seq) ge min($seq)
sum(1 to 42) ≡ 903
42 instance of xs:integer
'2007-02-13' castable as xs:date
'2007-02-13' cast as xs:date
if ( $i castable as xs:… ) then $i cast as xs:… else ()
<reference name="kau03"> <names type="author"> <person> <givenname>Roland</givenname> <surname>Kaufmann</surname> </person> </names> <date value="2003-05"/> <abstract> <richtext> <p>The work presented here extends an existing algorithm for testing if an inclusion relation exists between two markup schemata, to only take into account the parts of the grammar that have been used in a given subset of its language. Statistics for this purpose are gathered in combination with validation when documents are entered and are stored along with them in the repository. This modified subtyping relation is used to determine compatibility with the current database when a schema is upgraded.</p> </richtext> </abstract> <address>Bergen, Norway</address> <publisher type="university">University of Bergen</publisher> <title>Efficiently Locating Schema Incompatibilities in an Extensible Markup Language</title> <annotation> <richtext> <p>Keywords: <keywordref type="topic-xmlschema" weight="0.8"/>; </p> </richtext> </annotation> <identifier type="uri" resourceType="application/pdf">www.ub.uib.no/elpub/2003/h/413001/Hovedoppgave.pdf</identifier> <howpublished>Ph.D. Thesis</howpublished> </reference>
YYYY[-MM[-DD]]
topic-xml
(ignore the @weight)xref[@type eq 'updates']points to updated references (to their @name)