0

Is there a way to use regex in XSLT 1.0 with XML as the input and desired output? I am trying to use a test to confirm that a variable is in a timecode format, i.e. hh:mm:ss:ff.

The regular expression I currently am working with is:

[0-1][0-9]|2[0-3])(:|;)[0-5][0-9](:|;)[0-5][0-9](:|;)[0-9][0-9]

To produce a value time code in format hh:mm:ss:ff the following requirements must be met:

[hh = 00 - 19 or 20 - 23]
[; or :]
[mm = 00 - 59]
[; or :]
[ss = 00 -59]
[; or :]
[ff = 00 - 99]
hguza
  • 59
  • 2
  • 11
  • Possible duplicate of [How do I use a regular expression in XSLT 1.0?](http://stackoverflow.com/questions/8916208/how-do-i-use-a-regular-expression-in-xslt-1-0) – revo Aug 23 '16 at 17:14
  • It is slightly like this, however this expression is much more complicated than 1 number and 1 letter. I wanted to use an expression such as: ([0-1][0-9]|2[0-3])(:|;)[0-5][0-9](:|;)[0-5][0-9](:|;)[0-9][0-9](@[0-9]+(\.[0-9]{1,}){0,1}){0,1} – hguza Aug 23 '16 at 17:50
  • The answer, however, is going to be essentially the same as in the previous question. XSLT 1.0 does not support regular expressions; if your processor supports the EXSLT regular expressions functions (http://exslt.org/regexp/), use them; otherwise, fake it. The pattern you describe is not that hard to test and process. – C. M. Sperberg-McQueen Aug 23 '16 at 18:22
  • @Parfait Verifying the format of a text string is completely different from trying to *parse* (i.e. separate markup from payload) an XML/HTML document. – michael.hor257k Aug 23 '16 at 20:10
  • @hguza Which XSLT 1.0 processor are you using? – michael.hor257k Aug 23 '16 at 20:28
  • I will be importing into Vantage, currently I am testing on sublime text 3. I am not able to use EXSLT or XSLT 2.0 – hguza Aug 23 '16 at 20:34
  • @hguza I have no idea what Vantage is.See here how to identify the XSLT procesor: http://stackoverflow.com/questions/25244370/how-can-i-check-which-xslt-processor-is-being-used-in-solr/25245033#25245033 – michael.hor257k Aug 23 '16 at 21:35
  • Right now I am using Microsoft – hguza Aug 24 '16 at 12:56
  • See: https://msdn.microsoft.com/en-us/library/bb986124.aspx Although I believe the answer given below, which does not require any extensions is simple enough. – michael.hor257k Aug 24 '16 at 14:55

1 Answers1

0
  1. There is no regex support in XSLT 1.0.

  2. Your processor may offer a way to use regex as an extension.

  3. You can easily perform a partial test validating the format (but not the contents) of the variable as:

    translate($TC, '123456789;', '000000000:') ='00:00:00:00'
    

    This will return true for any string formatted as "##:##:##:##" (where any of the colons can be a semi-colon). However, it will not check for the hours being less than 24, or the minutes/seconds being less than 60.

    If you want such tests, you will have to add them individually, e.g.:

    substring($TC, 1, 2) < 24
    

    for the hours.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51