if … else : Para declarar condiciones
Adibide 1: Salida condicional
for $libro in doc("libreria")/libreria/libro
Comparaciones generales
Funtzio erabilgarria: between-inclusive (see also functx:between-inclusive
)
declare namespace functx = "http://www.functx.com";declare function functx:between-inclusive ($value as xs:anyAtomicType, $minValue as xs:anyAtomicType, $maxValue as xs:anyAtomicType) as xs:boolean {
$value >= $minValue and $value <= $maxValue };(: Example call :)let $prod := doc("catalog.xml")//product[1]return functx:between-inclusive ($prod/number, 1, 500)
Comparación nodos
Ejemplo 3.
for $prod in (doc("catalog.xml")/catalog/product)return if ($prod/@dept = 'ACC') then <accessoryNum>{data($prod/number)}</accessoryNum> else <otherNum>{data($prod/number)}</otherNum>
Ejemplo 4.
for $prod in (doc("catalog.xml")/catalog/product)return if ($prod/@dept = 'ACC') then (<accessoryNum>{data($prod/number)}</accessoryNum>, <accessoryName>{data($prod/name)}</accessoryName>) else <otherNum>{data($prod/number)}</otherNum>
Ejemplo 5.
for $prod in (doc("catalog.xml")/catalog/product)return if ($prod/@dept = 'ACC') then <accessory>{data($prod/number)}</accessory> else if ($prod/@dept = 'WMN') then <womens>{data($prod/number)}</womens> else if ($prod/@dept = 'MEN') then <mens>{data($prod/number)}</mens> else <other>{data($prod/number)}</other>
Ejemplo 6. not