Project

Profile

Help

Bug #4532 » al3-meta-info.xsl

Additional source of al3-dictionary.sef - Jeremy Cronk, 2020-05-08 18:47

 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:al3="http://www.ivansinsurance.com/acord/al3" xmlns:array="http://www.w3.org/2005/xpath-functions/array"
xmlns:nx="http://www.ivansinsurance.com/connect" xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array-ext="http://www.ivansinsurance.com/connect/array" xmlns:map-ext="http://www.ivansinsurance.com/connect/map"
exclude-result-prefixes="#all" expand-text="true" version="3.0">
<xsl:variable name="al3:meta" as="map(*)">
<xsl:variable name="parsed-data" select="'al3-meta.json' => resolve-uri($resource-dir) => json-doc()" as="map(*)"/>
<xsl:map>
<xsl:for-each select="map:keys($parsed-data)">
<xsl:map-entry key="." select="array-ext:shallow-flatten($parsed-data(.))"/>
</xsl:for-each>
</xsl:map>
</xsl:variable>
<xsl:variable name="al3:numeric-pattern" as="xs:string" select="'^([SN])(\d+)$'"/>
<xsl:variable name="al3:date-pattern" as="xs:string" select="'DT[68]'"/>
<xsl:variable name="al3:dde-lengths" select="$al3:meta?dde-definition"/>
<xsl:variable name="al3:header-labels" as="xs:string*" select="$al3:meta?header-labels"/>
<xsl:variable name="al3:groups-using-spaces" select="$al3:meta?groups-using-spaces"/>
<xsl:variable name="al3:elements-using-spaces" select="$al3:meta?elements-using-spaces"/>
<xsl:variable name="al3:paired-elements" as="map(*)">
<xsl:variable name="pairs" select="$al3:meta?paired-elements" as="array(*)*"/>
<xsl:variable name="reversed-pairs" select="$pairs => for-each(array:reverse#1)"/>
<xsl:sequence select="
let $seq := ($pairs, $reversed-pairs)
return
map-ext:entries($seq)"/>
</xsl:variable>
<xsl:variable name="al3:conditional-elements" as="map(*)">
<xsl:variable name="pairs" select="$al3:meta?conditional-elements" as="array(*)*"/>
<xsl:sequence select="map-ext:entries($pairs)"/>
</xsl:variable>
<xsl:variable name="al3:name-formats" as="map(xs:string, array(*)+)">
<xsl:map>
<xsl:for-each select="$al3:meta?name-formats">
<xsl:map-entry key="array:head(.)">
<xsl:variable name="pairs" select="array-ext:shallow-flatten(array:tail(.))"/>
<xsl:sequence select="$pairs ! array{ .?1, xs:integer(.?2) }"/>
</xsl:map-entry>
</xsl:for-each>
</xsl:map>
</xsl:variable>
<xsl:variable name="al3:omitted-groups-by-lobrc" select="$al3:meta?gcg-groups-by-lob"/>
<xsl:mode name="al3:element-types" on-multiple-match="fail" on-no-match="fail"/>
<xsl:function name="al3:omitted-groups" as="xs:string*">
<xsl:param name="lobrc" as="xs:string"/>
<xsl:param name="lob" as="xs:string"/>
<xsl:sequence select="$al3:omitted-groups-by-lobrc($lobrc)($lob) => array:flatten()"/>
</xsl:function>
<xsl:function name="al3:is-control-group" as="xs:boolean">
<xsl:param name="group-name" as="xs:string"/>
<xsl:sequence select="matches($group-name, '^[123]')"/>
</xsl:function>
<xsl:function name="al3:is-coverage-group" as="xs:boolean">
<xsl:param name="group-name" as="xs:string"/>
<xsl:variable name="coverages" as="xs:string*" select="'6CVH', '6CVA', '5CVG'"/>
<xsl:sequence select="$coverages = $group-name"/>
</xsl:function>
<xsl:function name="al3:is-group-description-element" as="xs:boolean">
<xsl:param name="element" as="xs:string"/>
<xsl:sequence select="ends-with($element, 'GR')"/>
</xsl:function>
<xsl:function name="al3:test-element-type" cache="yes">
<xsl:param name="element" as="xs:string"/>
<xsl:apply-templates select="$element" mode="al3:element-types"/>
</xsl:function>
<xsl:function name="al3:is-data-group" as="xs:boolean">
<xsl:param name="group-name" as="xs:string"/>
<xsl:sequence select="not(al3:is-control-group($group-name))"/>
</xsl:function>
<xsl:function name="al3:is-empty" as="xs:boolean">
<xsl:param name="value" as="xs:string"/>
<xsl:sequence select="matches($value, '^\s+$|^\?+$')"/>
</xsl:function>
<xsl:function name="al3:is-consistent" as="xs:boolean">
<xsl:param name="group-string" as="xs:string"/>
<xsl:try>
<xsl:variable name="expected-length"
select="
$group-string
=> substring(5, 3)
=> xs:integer()"/>
<xsl:sequence select="string-length($group-string) = $expected-length"/>
<xsl:catch>
<xsl:sequence
select="
error(QName(namespace-uri-for-prefix('al3', document('')/xsl:stylesheet), 'MalformedGroupError'),
'The input string ''' || $group-string || ''' does not contain a valid length')"
/>
</xsl:catch>
</xsl:try>
</xsl:function>
<xsl:function name="al3:is-data-element" as="xs:boolean">
<xsl:param name="element" as="xs:string"/>
<xsl:sequence select="al3:test-element-type($element) instance of element(al3:data-element)"/>
</xsl:function>
<xsl:template match="." mode="al3:element-types">
<al3:other-info/>
</xsl:template>
<xsl:template match=".[ends-with(., 'GR')]" priority="2" mode="al3:element-types">
<al3:group-description/>
</xsl:template>
<xsl:template match=".[ends-with(., '00')]" priority="2" mode="al3:element-types">
<al3:header-info/>
</xsl:template>
<xsl:template match=".[matches(., '^\d[A-Z]{3}[0-9A-Z]{2}$')]" priority="1" mode="al3:element-types">
<al3:data-element/>
</xsl:template>
</xsl:stylesheet>
(4-4/6)