Skip to content

Commit

Permalink
not sure about ietf, without using a much longer regex
Browse files Browse the repository at this point in the history
  • Loading branch information
fordmadox committed Feb 24, 2022
1 parent b11ce29 commit 8f2fe1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions source/modules/schematron/shared-rules.sch
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@

<!-- until we have a better way with dealing with "other" as a value, etc.-->
<sch:let name="check-language-codes" value="if (*/*:control/@languageEncoding = ('otherLanguageEncoding', 'ietf-bcp-47')) then false() else true()"/>
<sch:let name="check-ietf-codes" value="if (*/*:control[@languageEncoding eq 'ietf-bcp-47'][not(@scriptEncoding)]) then true() else false()"/>
<sch:let name="check-country-codes" value="if (*/*:control/@countryEncoding eq 'otherCountryEncoding') then false() else true()"/>
<sch:let name="check-script-codes" value="if (*/*:control/@scriptEncoding eq 'otherScriptEncoding') then false() else true()"/>
<sch:let name="check-repository-codes" value="if (*/*:control/@repositoryEncoding eq 'otherRepositoryEncoding') then false() else true()"/>

<!-- VARIABLE iso15511Pattern -->
<sch:let name="iso15511Pattern" value="'(^([A-Z]{2})|([a-zA-Z]{1})|([a-zA-Z]{3,4}))(-[a-zA-Z0-9:/\-]{1,11})$'"/>

<sch:let name="ietfPattern" value="'^[A-Za-z]{2,4}([_-][A-Za-z]{4})?([_-]([A-Za-z]{2}|[0-9]{3}))?$'"/>


<!-- LANGUAGE CODE TESTS (in process) -->
<sch:pattern>
<sch:rule context="*[exists(@languageCode | @languageOfElement)][$check-language-codes]">
<!-- for every @lang or @langcode attribute, test that it is equal to a value in the relevant language code list -->
<sch:assert test="every $l in (@languageCode | @languageOfElement) satisfies normalize-space($l) = $valid-language-codes">The <sch:name/> element's lang or langcode attribute should contain a value from the <xsl:value-of select="$active-language-code-key"/> codelist.</sch:assert>
</sch:rule>

<sch:rule context="*[exists(@languageCode | @languageOfElement)][$check-ietf-codes]">
<!-- for every @lang or @langcode attribute, test that it is equal to a value in the relevant language code list -->
<sch:assert test="every $l in (@languageCode | @languageOfElement) satisfies matches(normalize-space($l), $ietfPattern)">The <sch:name/> element's lang or langcode attribute should contain a value from the 'ietf-bcp-47' codelist.</sch:assert>
</sch:rule>
</sch:pattern>

<!-- COUNTRY CODES (in process) -->
Expand Down
8 changes: 8 additions & 0 deletions xml-schemas/eac-cpf/schematron/eac.sch
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@

<!-- until we have a better way with dealing with "other" as a value, etc.-->
<sch:let name="check-language-codes" value="if (*/*:control/@languageEncoding = ('otherLanguageEncoding', 'ietf-bcp-47')) then false() else true()"/>
<sch:let name="check-ietf-codes" value="if (*/*:control[@languageEncoding eq 'ietf-bcp-47'][not(@scriptEncoding)]) then true() else false()"/>
<sch:let name="check-country-codes" value="if (*/*:control/@countryEncoding eq 'otherCountryEncoding') then false() else true()"/>
<sch:let name="check-script-codes" value="if (*/*:control/@scriptEncoding eq 'otherScriptEncoding') then false() else true()"/>
<sch:let name="check-repository-codes" value="if (*/*:control/@repositoryEncoding eq 'otherRepositoryEncoding') then false() else true()"/>

<!-- VARIABLE iso15511Pattern -->
<sch:let name="iso15511Pattern" value="'(^([A-Z]{2})|([a-zA-Z]{1})|([a-zA-Z]{3,4}))(-[a-zA-Z0-9:/\-]{1,11})$'"/>

<sch:let name="ietfPattern" value="'^[A-Za-z]{2,4}([_-][A-Za-z]{4})?([_-]([A-Za-z]{2}|[0-9]{3}))?$'"/>


<!-- LANGUAGE CODE TESTS (in process) -->
<sch:pattern>
<sch:rule context="*[exists(@languageCode | @languageOfElement)][$check-language-codes]">
<!-- for every @lang or @langcode attribute, test that it is equal to a value in the relevant language code list -->
<sch:assert test="every $l in (@languageCode | @languageOfElement) satisfies normalize-space($l) = $valid-language-codes">The <sch:name/> element's lang or langcode attribute should contain a value from the <xsl:value-of select="$active-language-code-key"/> codelist.</sch:assert>
</sch:rule>

<sch:rule context="*[exists(@languageCode | @languageOfElement)][$check-ietf-codes]">
<!-- for every @lang or @langcode attribute, test that it is equal to a value in the relevant language code list -->
<sch:assert test="every $l in (@languageCode | @languageOfElement) satisfies matches(normalize-space($l), $ietfPattern)">The <sch:name/> element's lang or langcode attribute should contain a value from the 'ietf-bcp-47' codelist.</sch:assert>
</sch:rule>
</sch:pattern>

<!-- COUNTRY CODES (in process) -->
Expand Down

0 comments on commit 8f2fe1d

Please sign in to comment.