Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You say that you're using Saxon. If this is the recent version (8.x, 9.x), then it's an XSLT 2.0 processor, and as such, it supports the <code>xsl:analyze-string</code> instruction for parsing strings using regular expressions, and XML Schema primitive datatypes, including <code>xs:date</code>. So you can use regex to split date into components, then convert the result to ISO 8601 date, try to convert it to <code>xs:date</code> for validation of month and day (this should handle leap years etc correctly):</p> <pre><code>&lt;xsl:variable name="date-string" select="..."/&gt; ... &lt;xsl:analyze-string select="$date-string" regex="^(\d{4})(\d{2})(\d{2})$"&gt; &lt;xsl:matching-substring&gt; &lt;xsl:variable name="$year" select="xs:integer(regex-group(1))"/&gt; &lt;xsl:variable name="$month" select="xs:integer(regex-group(2))"/&gt; &lt;xsl:variable name="$day" select="xs:integer(regex-group(3))"/&gt; &lt;xsl:variable name="$date-iso" select="concat($year, '-', $month, '-', $day)" /&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$date-iso castable as xs:date"&gt; &lt;xsl:variable name="$date" select="$date-iso cast as xs:date" /&gt; &lt;!-- $date now contains an xs:date value, which you can work with using XPath 2.0 date functions --&gt; ... &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;!-- $date-string was in YYYYMMDD format, but values for some of components were incorrect (e.g. February 31). --&gt; ... &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:matching-substring&gt; &lt;xsl:non-matching-substring&gt; &lt;!-- $date-string wasn't in YYYYMMDD format at all --&gt; ... &lt;/xsl:non-matching-substring&gt; &lt;/xsl:analyze-string&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload