Last active
October 18, 2017 18:54
-
-
Save WaxCylinderRevival/576e7d149f646cc109e6270e33e03d86 to your computer and use it in GitHub Desktop.
Test of local function to find date string(s) with common FRUS date pattern and wrap with date element
This file contains 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
import module namespace functx="http://www.functx.com" at "http://www.xqueryfunctions.com/xq/functx-1.0-nodoc-2007-01.xq"; | |
(: declare namespace date-processing='https://history.state.gov/ns/xquery/dates' :) | |
declare function local:find-date-strings | |
( $textWithDates as xs:string? ) as element()* { | |
for $textString in | |
$textWithDates => data() => serialize() => normalize-space() => functx:get-matches('((\d{1,2}[(st)(d)(nd)(rd)(th)]*\s+(January|February|March|April|May|June|July|August|September|October|November|December),*\s+\d{4})|((January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}[(st)(nd)(d)(rd)(th)]*,\s+\d{4}))') => serialize() => functx:trim() => tokenize('\s\s+') | |
return <date>{$textString}</date> | |
}; | |
let $input := <head>The first date is <hi>February 2d, 1865</hi>. The next date is March 1, 2010. The <strong>third</strong> date is <hi rend="italic">31st July</hi> 2015.</head> | |
let $dates := local:find-date-strings($input) | |
return <results>{$dates}</results> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Without functx:trim, there's a leading space in the first entry: