Suppose you have a timestamp string, and want to check whether it fits to one of the following formats with leading and trailing spaces:
We decided to use regex and its capture groups to extract timestamp parts. This left us with only solution: xsl:analyze-string instruction. It took a couple more minutes to reach a final solution:
xsl:analyze-string
<xsl:variable name="parts" as="xs:string*"> <xsl:analyze-string select="$value" regex=" ^\s*(\d\d\d\d)-(\d\d)-(\d\d) (-(\d\d)\.(\d\d)\.(\d\d)(\.(\d\d\d\d\d\d))?)?\s*$" flags="x"> <xsl:matching-substring> <xsl:sequence select="regex-group(1)"/> <xsl:sequence select="regex-group(2)"/> <xsl:sequence select="regex-group(3)"/> <xsl:sequence select="regex-group(5)"/> <xsl:sequence select="regex-group(6)"/> <xsl:sequence select="regex-group(7)"/> <xsl:sequence select="regex-group(9)"/> </xsl:matching-substring> </xsl:analyze-string> </xsl:variable> <xsl:choose> <xsl:when test="exists($parts)"> ... </xsl:when> <xsl:otherwise> ... </xsl:otherwise> </xsl:choose>
How would you solve the problem? Is it the best solution?
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u