Project

Profile

Help

Bug #4532 » al3-dictionary.xsl

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

 
<xsl:package name="com.ivans.connect.acord.al3" package-version="0.1.0"
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" exclude-result-prefixes="#all" version="3.0">
<xsl:key name="element-definitions" match="Definition" use="@groupelement"/>
<xsl:key name="elements-by-group" match="Definition" use="@group"/>
<xsl:key name="elements-by-class" match="Definition" use="@data_class"/>
<xsl:include href="al3-meta-info.xsl"/>
<xsl:use-package name="com.ivans.connect.utils.map" package-version="0.1.0"/>
<xsl:use-package name="com.ivans.connect.utils.array" package-version="0.1.0"/>
<xsl:expose visibility="public" component="function" names="al3:*"/>
<xsl:expose visibility="public" component="variable" names="al3:*"/>
<xsl:variable name="resource-dir" select="resolve-uri('../resources/', static-base-uri())" as="xs:anyURI"/>
<!-- XML version of the ACORD AL3 data dictionary text file -->
<xsl:variable name="al3:data-dictionary" select="document(resolve-uri('data-dictionary.xml', $resource-dir))"/>
<!-- Not sure if this is enough or if it would be better to have a function that returns element definitions by the class
passed in - what would a function like that be called? Is there any other purpose for one? -->
<xsl:variable name="al3:name-elements" as="xs:string*" select="key('elements-by-class', 'NM', $al3:data-dictionary)/@groupelement"/>
<xsl:function name="al3:start-position" as="xs:decimal?">
<xsl:param name="element" as="element(Definition)"/>
<xsl:sequence select="xs:decimal($element/@start)"/>
</xsl:function>
<xsl:function name="al3:printable-elements">
<xsl:param name="elements" as="element(Definition)*"/>
<xsl:sequence select="$elements[not(number(@length) = 0)]"/>
</xsl:function>
<xsl:function name="al3:sort-elements">
<xsl:param name="elements" as="element(Definition)*"/>
<xsl:sequence select="sort($elements, default-collation(), al3:start-position#1)"/>
</xsl:function>
<!-- return a sorted list of element definitions belonging to the group passed in -->
<xsl:function name="al3:group-definition" as="element(Definition)*">
<xsl:param name="group" as="xs:string"/>
<xsl:variable name="elements" select="key('elements-by-group', $group, $al3:data-dictionary)"/>
<xsl:sequence select="$elements => al3:sort-elements() => al3:printable-elements()"/>
</xsl:function>
<xsl:function name="al3:element-definition" as="element(Definition)" visibility="public">
<xsl:param name="element-name" as="xs:string"/>
<xsl:variable name="lookup-value"
select="
if (matches($element-name, '\d{2}$')) then
$element-name
else
($element-name
|| '00')"/>
<xsl:sequence select="key('element-definitions', $lookup-value, $al3:data-dictionary)"/>
</xsl:function>
<xsl:function name="al3:group-standard" as="xs:string">
<xsl:param name="group-name" as="xs:string"/>
<xsl:variable name="definition" select="al3:element-definition($group-name)"/>
<xsl:sequence select="$definition/@standard"/>
</xsl:function>
<xsl:function name="al3:group-version" as="xs:string">
<xsl:param name="group-name" as="xs:string"/>
<xsl:variable name="definition" select="al3:element-definition($group-name)"/>
<xsl:sequence select="$definition/@version"/>
</xsl:function>
<xsl:function name="al3:data-elements" as="element(Definition)*">
<xsl:param name="group-name" as="xs:string"/>
<xsl:sequence
select="
filter(al3:group-definition($group-name), function ($dfn) {
al3:is-data-element($dfn/@groupelement)
})"
/>
</xsl:function>
</xsl:package>
(3-3/6)