[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
The XML Path Language (XPath) is one of the most useful and frequently used languages in the are of XML technologies. In its version 1.0, it is used in technologies such as XSLT, XSD, DOM, and XML Tools. With XPath 2.0, the language has been greatly extended, the new version of XPath is the foundation for XSLT 2.0 and XQuery. XPath 2.0 provides support for regular expression matching, typed expressions, and contains language constructs for conditional and repeated evaluation.
//img[not(@alt)]
count(//img)
/descendant::img[3]/@src
starts-with(/html/@lang, 'en')
Sequencesare XPath's mechanism where these types show up
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 ()
<listing src="xlinked-class.xml" line="81-98"/>
string-join(tokenize( if ( exists(@encoding) ) then unparsed-text($fileuri, @encoding) else unparsed-text($fileuri), '\r?\n')[(position() ge number(tokenize(current()/@line, '\-')[1])) and (position() le number(tokenize(current()/@line, '\-')[2]))], '
')
control flowis based on predicates
emulatecontrol flow
if ( … ) then … else …
if ( @sex eq 'm' ) then 'Sir' else 'Madam'
if ( @sex eq 'm' ) then 'Sir' else if ( @sex eq 'f' ) then 'Madam' else 'Whatever'
<names> <name> <first>Erik</first> <last>Wilde</last> </name> <name> <last>Hasan</last> </name> </names>
first | last[not(../first)]
<xsl:variable name="name"> <xsl:choose> <xsl:when test="first"> <xsl:value-of select="first"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="last"/> </xsl:otherwise> </xsl:choose> </xsl:variable>
if ( exists(first) ) then first else last
sequencesis central to this concept
for $… in … return …
for $i in //name return $i/last
for $i in //name return if ( exists($i/first) ) then $i/first else $i/last
/names/name/last
for $i in /names return for $j in $i/name return $j/last
for $i in 1 to 10 return $i
//last/../..
for $i in //last return for $j in $i/.. return $j/..
sequencesis central to this concept
( some | every ) $… in … satisfies …
some $i in //*[@xlink:type='locator']/@xlink:href satisfies $i eq $query-uri
every $i in //li/@id satisfies //*[@xlink:type='locator'][@xlink:href=concat('#', $i)]