XPath intensif

Fonctions sur les chaînes de caractères

Fonctions d'assemblage désassemblage

Fonction

Description

fn:codepoints-to-string($arg as xs:integer*) as xs:string

Assemble une séquence de caractères (exprimés par leur code UNICODE) en chaîne de caractères

fn:string-to-codepoints($arg as xs:string?) as xs:integer*

Désassemble une chaîne de caractères en séquences de nombres représentant leur code UNICODE.

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:codepoints-to-string((66, 65, 67, 72))
fn:codepoints-to-string((66, 65, 67, 72))

Retourne "BACH"

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:string-to-codepoints("Thérèse")
fn:string-to-codepoints("Thérèse")

Retourne (84, 104, 233, 114, 232, 115, 101)

Fonctions de comparaison

Fonction

Description

fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer?

fn:compare( $comparand1 as xs:string?, $comparand2 as xs:string?, $collation as xs:string) as xs:integer?

Retourne :

  • -1 si $comparand1 est avant $comparand2

  • 0 si egalité

  • 1 si après

en fonction de la collation choisie.

fn:codepoint-equal( $comparand1 as xs:string?, $comparand2 as xs:string?) as xs:boolean?

Comparaison d'égalité stricte entre les chaînes de caractères (code UNICODE)

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:compare('abc', 'abc')
fn:compare('abc', 'abc')

Retourne 0

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:compare('Strasse', 'Straße')
fn:compare('Strasse', 'Straße')

Retourne 0 (car dans collation par défaut : ß = ss)

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:compare('Strassen', 'Straße')
fn:compare('Strassen', 'Straße')

Retourne 1

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:compare("hello", "world")
fn:compare("hello", "world")

Retourne -1

Fonctions sur les chaînes de caractères

Fonction

Description

fn:concat( $arg1 as xs:anyAtomicType?,

$arg2 as xs:anyAtomicType?,

... ) as xs:string

Concaténation

fn:string-join($arg1 as xs:string*) as xs:string

fn:string-join($arg1 as xs:string*, $arg2 as xs:string) as xs:string

Concaténation utilisant un séparateur

fn:substring($sourceString as xs:string?, $start as xs:double) as xs:string

fn:substring( $sourceString as xs:string?, $start as xs:double, $length as xs:double) as xs:string

Extraction de chaîne de caractères

fn:string-length($arg as xs:string?) as xs:integer

Longueur de la chaîne de caractères

fn:normalize-space($arg as xs:string?) as xs:string

Suppression des espaces "inutiles"

fn:upper-case($arg as xs:string?) as xs:string

Transforme le texte en lettres majuscules

fn:lower-case($arg as xs:string?) as xs:string

Transforme le texte en lettres minuscules

fn:translate( $arg as xs:string?, $mapString as xs:string, $transString as xs:string) as xs:string

Transforme la chaîne de caractères en remplaçant/supprimant des caractères par d'autres

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:string-join(('Now', 'is', 'the', 'time', '...'), ' ')
fn:string-join(('Now', 'is', 'the', 'time', '...'), ' ')

Retourne "Now is the time ..."

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:normalize-space(" The    wealthy curled darlings                                         of    our    nation. ")
fn:normalize-space(" The    wealthy curled darlings                                         of    our    nation. ")

Retourne "The wealthy curled darlings of our nation."

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:translate("bar","abc","ABC")
fn:translate("bar","abc","ABC")

Retourne "BAr"

Fonctions de comparaison de sous-chaînes

Fonction

Description

fn:contains($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean

fn:contains( $arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean

Détermine si une chaîne en contient une autre

(possibilité de préciser la collation)

fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean

fn:starts-with( $arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean

Détermine si une chaîne commence par une autre

(possibilité de préciser la collation)

fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean

fn:ends-with( $arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean

Détermine si une chaîne se termine par une autre

(possibilité de préciser la collation)

fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?) as xs:string

fn:substring-before( $arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string

Récupère la chaîne de caractères précédente d'une autre

(possibilité de préciser la collation)

fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?) as xs:string

fn:substring-after( $arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string

Récupère la chaîne de caractères suivante d'une autre

(possibilité de préciser la collation)

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:substring-before ( "tattoo", "attoo")
fn:substring-before ( "tattoo", "attoo")

Retourne "t"

Fonctions utilisant les expressions régulières

Pour plus d'information sur les expressions régulières, se référer à : http://www.w3.org/TR/xpath-functions-30/#regex-syntax

Fonction

Description

fn:matches($input as xs:string?, $pattern as xs:string) as xs:boolean

fn:matches( $input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:boolean

Retourne true si une chaîne de caractères match l'expression régulière

fn:replace( $input as xs:string?, $pattern as xs:string, $replacement as xs:string) as xs:string

fn:replace( $input as xs:string?, $pattern as xs:string, $replacement as xs:string, $flags as xs:string) as xs:string

Remplace une sous-chaîne de caractères qui est conforme à une expression régulière

fn:tokenize($input as xs:string?, $pattern as xs:string) as xs:string*

fn:tokenize( $input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:string*

Découpe une chaîne de caractères par un séparateur conforme à une expression régulière

Pour les Flags disponibles se référer à : http://www.w3.org/TR/xpath-functions-30/#flags

Exemple

CTRL+C pour copier, CTRL+V pour coller
1
fn:tokenize("abracadabra", "(ab)|(a)")
fn:tokenize("abracadabra", "(ab)|(a)")

Retourne ("", "r", "c", "d", "r", "")

PrécédentPrécédentSuivantSuivant
AccueilAccueilImprimerImprimer Jean-Baptiste Martin, 2015 (Contributions : Stéphane Crozat, les étudiants de NF29) Paternité - Partage des Conditions Initiales à l'IdentiqueRéalisé avec Scenari (nouvelle fenêtre)