Can external scripts be used inside Schematron rules?

264 views Asked by At

Is there a way to call Javascript functions in a Schematron rules file?

I'm pretty sure that the engine takes the rules file and generates an XSLT from it but was wondering if I can somehow include scripts in that rules file that will ultimately wind up in the XSLT?

Amongst other things it would be useful for validation rules that involve a lot of string parsing such as this:

<rule context="nar:versionCreated">
  <assert test="string-length(translate(substring(.,1, 1), '12','')) = 0">versionCreated is an iso date/time (r20a1).</assert>
  <assert test="string-length(translate(substring(.,2, 3), '0123456789','')) = 0">versionCreated is an iso date/time (r20a2).</assert>
  <assert test="substring(.,5, 1) = '-'">versionCreated is an iso date/time (r20a3).</assert>
  <assert test="string-length(translate(substring(.,6, 1), '01','')) = 0">versionCreated is an iso date/time (r20a4).</assert>
  <assert test="string-length(translate(substring(.,7, 1), '0123456789','')) = 0">versionCreated is an iso date/time (r20a5).</assert>
  <assert test="substring(.,8, 1) = '-'">versionCreated is an iso date/time (r20a6).</assert>
  <assert test="string-length(translate(substring(.,9, 1), '0123','')) = 0">versionCreated is an iso date/time (r20a7).</assert>
  <assert test="string-length(translate(substring(.,10, 1), '0123456789','')) = 0">versionCreated is an iso date/time (r20a8).</assert>
  <assert test="substring(.,11, 1) = 'T'">versionCreated is an iso date/time (r20a9).</assert>
  <assert test="string-length(translate(substring(.,12, 1), '012','')) = 0">versionCreated is an iso date/time (r20a10).</assert>
  <assert test="string-length(translate(substring(.,13, 1), '0123456789','')) = 0">versionCreated is an iso date/time (r20a11).</assert>
  <assert test="substring(.,14, 1) = ':'">versionCreated is an iso date/time (r20a12).</assert>
  <assert test="string-length(translate(substring(.,15, 1), '012345','')) = 0">versionCreated is an iso date/time (r20a13).</assert>
  <assert test="string-length(translate(substring(.,16, 1), '0123456789','')) = 0">versionCreated is an iso date/time (r20a14).</assert>
  <assert test="substring(.,17, 1) = ':'">versionCreated is an iso date/time (r20a15).</assert>
  <assert test="string-length(translate(substring(.,18, 1), '012345','')) = 0">versionCreated is an iso date/time (r20a16).</assert>
  <assert test="string-length(translate(substring(.,19, 1), '0123456789','')) = 0">versionCreated is an iso date/time (r20a17).</assert>
  <assert test="substring(.,20, 1) = 'Z' or substring(.,20, 1) = '+' or substring(.,20, 1) = '-'">versionCreated is an iso date/time (r20a18).</assert>
  <assert test="string-length(translate(substring(.,21, 1), '012345','')) = 0">versionCreated is an iso date/time (r20a19).</assert>
  <assert test="string-length(translate(substring(.,22, 1), '0123456789','')) = 0">versionCreated is an iso date/time (r20a20).</assert>
  <assert test="substring(.,23, 1) = ':' or substring(.,23, 1) = ''">versionCreated is an iso date/time (r20a21).</assert>
  <assert test="string-length(translate(substring(.,24, 1), '012345','')) = 0">versionCreated is an iso date/time (r20a22).</assert>
  <assert test="string-length(translate(substring(.,25, 1), '0123456789','')) = 0">versionCreated is an iso date/time (r20a23).</assert>
</rule>

And turn it into something like:

<rule context="nar:versionCreated">
  <assert test="jscript:IsISOFormattedDateTime(.)">versionCreated is not a properly formatted date/time.</assert>
</rule>

Thanks for any help.

1

There are 1 answers

0
vittore On BEST ANSWER

I belive that you are looking for abstract patterns. It is not script but you can reuse patterns.

Also I found this question Formatting a Date (Sharepoint Designer) So you might try to pull out schema from sharepoint and reuse it in schematron.