Skip to content

Commit

Permalink
Support phase-specific validation root
Browse files Browse the repository at this point in the history
  • Loading branch information
dmj committed Sep 30, 2024
1 parent e597175 commit 51f0524
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions src/main/resources/content/transpile.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ SOFTWARE.
<xsl:template match="sch:schema" as="element(xsl:stylesheet)" mode="schxslt:transpile">

<xsl:variable name="phase" as="xs:string" select="if ($schxslt:phase = ('#DEFAULT', '')) then (@defaultPhase, '#ALL')[1] else $schxslt:phase"/>
<xsl:variable name="validation-root" as="xs:string" select="(sch:phase[@id = $phase]/@from, 'root()')[1]"/>
<xsl:variable name="patterns" as="map(xs:string, element(sch:pattern)+)">
<xsl:map>
<xsl:for-each-group select="key('schxslt:patternByPhaseId', $phase)" group-by="string(@documents)">
Expand All @@ -324,6 +325,8 @@ SOFTWARE.

<xsl:sequence select="xsl:accumulator | xsl:function | xsl:include | xsl:import | xsl:import-schema | xsl:key | xsl:use-package"/>

<alias:mode name="schxslt:validate" on-no-match="shallow-skip" streamable="{$schxslt:streamable}"/>

<xsl:for-each select="map:keys($patterns)">
<alias:mode name="{.}" on-no-match="shallow-skip" streamable="{$schxslt:streamable}"/>
<alias:template match="*" mode="{.}" priority="-10">
Expand All @@ -345,37 +348,43 @@ SOFTWARE.
<svrl:ns-prefix-in-attribute-values prefix="{@prefix}" uri="{@uri}"/>
</xsl:for-each>
<xsl:comment>SchXslt2 Core {$schxslt:version}</xsl:comment>
<xsl:for-each select="map:keys($patterns)">
<xsl:variable name="groupId" as="xs:string" select="."/>
<xsl:for-each select="map:get($patterns, $groupId)">
<svrl:active-pattern>
<xsl:sequence select="@id"/>
<alias:attribute name="documents" select="{if (@documents) then @documents else 'document-uri(.)'}"/>
</svrl:active-pattern>
</xsl:for-each>

<xsl:choose>
<xsl:when test="map:get($patterns, $groupId)[1]/@documents">
<alias:for-each select="{map:get($patterns, $groupId)[1]/@documents}">
<alias:source-document href="{{.}}">
<xsl:call-template name="schxslt:dispatch-validation-group">
<xsl:with-param name="groupId" as="xs:string" select="$groupId"/>
</xsl:call-template>
</alias:source-document>
</alias:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="schxslt:dispatch-validation-group">
<xsl:with-param name="groupId" as="xs:string" select="$groupId"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>

</xsl:for-each>
<alias:apply-templates select="." mode="schxslt:validate"/>
</svrl:schematron-output>

</alias:template>

<alias:template match="{$validation-root}" mode="schxslt:validate">
<xsl:for-each select="map:keys($patterns)">
<xsl:variable name="groupId" as="xs:string" select="."/>
<xsl:for-each select="map:get($patterns, $groupId)">
<svrl:active-pattern>
<xsl:sequence select="@id"/>
<alias:attribute name="documents" select="{if (@documents) then @documents else 'document-uri(.)'}"/>
</svrl:active-pattern>
</xsl:for-each>

<xsl:choose>
<xsl:when test="map:get($patterns, $groupId)[1]/@documents">
<alias:for-each select="{map:get($patterns, $groupId)[1]/@documents}">
<alias:source-document href="{{.}}">
<xsl:call-template name="schxslt:dispatch-validation-group">
<xsl:with-param name="groupId" as="xs:string" select="$groupId"/>
</xsl:call-template>
</alias:source-document>
</alias:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="schxslt:dispatch-validation-group">
<xsl:with-param name="groupId" as="xs:string" select="$groupId"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>

</xsl:for-each>

</alias:template>

</alias:stylesheet>

</xsl:template>
Expand Down

0 comments on commit 51f0524

Please sign in to comment.