Last active
August 29, 2015 14:25
-
-
Save ebruchez/be9f9f093e368c22b39e to your computer and use it in GitHub Desktop.
Example of indentation of a pretty large XPath 2 expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for $raw in . return | |
for $query in instance('fr-search-instance')/query[$detail-position + 1] return | |
for $control in $query/@control return | |
if ($control = 'textarea') then | |
if (string-length($raw) > 20) then | |
concat(substring($raw, 1, 20), '...') | |
else | |
$raw | |
else if (frf:isMultipleSelectionControl($control)) then | |
string-join( | |
for $code in xxf:split($raw) return | |
($form-resources/*[local-name() = $query/@name]/item[value = $code]/label, $code)[1], | |
', ' | |
) | |
else if (frf:isSingleSelectionControl($control)) then | |
for $code in $raw return | |
($form-resources/*[local-name() = $query/@name]/item[value = $code]/label, $code)[1] | |
else if ($control = 'secret') then | |
if (normalize-space($raw) = '') then | |
'' | |
else | |
'••••••••' | |
else | |
for $type in substring-after($query/@type, ':') return | |
if ($type = 'date') then | |
if ($raw castable as xs:date) then | |
format-date( | |
xs:date($raw), | |
$fr-resources/summary/formats/date, | |
xxf:lang(), | |
(), | |
() | |
) | |
else | |
$raw | |
else if ($type = 'time') then | |
if ($raw castable as xs:time) then | |
format-time( | |
xs:time($raw), | |
$fr-resources/summary/formats/time, | |
xxf:lang(), | |
(), | |
() | |
) | |
else | |
$raw | |
else if ($type = 'dateTime') then | |
if ($raw castable as xs:dateTime) then | |
format-dateTime( | |
xs:dateTime($raw), | |
$fr-resources/summary/formats/dateTime, | |
xxf:lang(), | |
(), | |
() | |
) | |
else | |
$raw | |
else if ($type = 'dayTimeDuration') then | |
if ($raw castable as xs:dayTimeDuration) then | |
string-join( | |
( | |
if (days-from-duration($raw) = 0) then | |
() | |
else | |
concat(days-from-duration($raw), ' d'), | |
if (hours-from-duration($raw) = 0) then | |
() | |
else | |
concat(hours-from-duration($raw), ' h'), | |
if (minutes-from-duration($raw) = 0) then | |
() | |
else | |
concat(minutes-from-duration($raw), ' min'), | |
if (seconds-from-duration($raw) = 0) then | |
() | |
else | |
concat(seconds-from-duration($raw), ' sec') | |
), | |
' ' | |
) | |
else | |
$raw | |
else | |
$raw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment