Skip to content

Commit

Permalink
Fixed some bugs, still more to go:
Browse files Browse the repository at this point in the history
 * Yup, @joeytakeda’s version was right, need the “//” on the
   exception to avoid processing twice.
 * Removed entire “declarations:” block, as everything is already
   processed elsewhere.
 * Improved pattern name creation (in case there is no ancestor
   with ident=, but there is one with xml:id=, take that; if not,
   and if in constraintDecl, just say so).
 * Don’t process sch:ns elements in constraintDecl twice.
HOWEVER, I am comitting this now as I have just decided to
re-write the main "/key('CONSTRAINTs',  )" loop,
as it is giving me trouble, and probably should be an apply-
templates, anyway.
  • Loading branch information
sydb committed Jan 20, 2025
1 parent af7291c commit 2ff142b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
36 changes: 23 additions & 13 deletions odds/extract-isosch.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -356,39 +356,35 @@ of this software, even if advised of the possibility of such damage.
schema that does not perform the desired constraint tests properly.</xsl:message>
</xsl:if>

<xsl:if test="$decorated//tei:constraintDecl[ @scheme eq 'schematron']/*[ not( self::sch:ns ) ]">
<xsl:call-template name="blockComment">
<xsl:with-param name="content" select="'declarations:'"/>
</xsl:call-template>
<xsl:apply-templates mode="copy"
select="//tei:constraintDecl[ @scheme eq 'schematron']/*[not(self::sch:ns)]"/>
</xsl:if>

<xsl:if test="key('CONSTRAINTs', $langs )">
<xsl:if test="key('CONSTRAINTs', $langs )[ not( self::sch:ns ) ]">
<xsl:variable name="N"
select="', of which there are '||count( key('CONSTRAINTs', $langs, $root )/self::constraint )"/>
select="', of which there are '||count( key('CONSTRAINTs', $langs, $root )/*[ not( self::sch:ns ) ] )"/>
<xsl:call-template name="blockComment">
<xsl:with-param name="content" select="'constraints in '||string-join( $langs, ', ')||$N"/>
</xsl:call-template>
</xsl:if>
<xsl:for-each select="$root/key('CONSTRAINTs', $langs )">
<xsl:for-each select="$root/key('CONSTRAINTs', $langs )[ not( self::sch:ns ) ]">
<xsl:variable name="patID" select="tei:makePatternID(.)"/>
<xsl:message select="'DEBUG: processing '||$patID"/>
<xsl:choose>
<xsl:when test="sch:pattern">
<xsl:message select="'debug: a pattern child'"/>
<!-- IF there is a child <pattern>, we just copy over all children, no tweaking -->
<xsl:apply-templates select="node()">
<!-- they all get handed $patID, but only the template for 'pattern' uses it -->
<xsl:with-param name="patID" select="$patID"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="sch:rule">
<xsl:message select="'debug: a rule child'"/>
<!-- IF there is no <pattern>, but there is a <rule>, copy over all children -->
<!-- into a newly created <pattern> wrapper -->
<pattern id="{$patID}">
<xsl:apply-templates select="node()"/>
</pattern>
</xsl:when>
<xsl:when test="sch:assert | sch:report | sch:extends">
<xsl:message select="'debug: some other child'"/>
<!-- IF there is no <pattern> nor <rule> child, but there is a child that -->
<!-- requires being wrapped in a rule, create both <rule> and <pattern> -->
<!-- wrappers for them, making HERE the context. NOTE: As of 2025-03-15 -->
Expand All @@ -402,6 +398,7 @@ of this software, even if advised of the possibility of such damage.
</pattern>
</xsl:when>
<xsl:otherwise>
<xsl:message select="'debug: OTHERWISE'"/>
<!-- IF there is neither a <pattern> nor a <rule>, nor a child that would -->
<!-- require being wrapped in those, just copy over whatever we have -->
<xsl:apply-templates select="node()"/>
Expand Down Expand Up @@ -596,15 +593,28 @@ of this software, even if advised of the possibility of such damage.
</d:doc>
<xsl:function name="tei:makePatternID" as="xs:string">
<xsl:param name="context"/>
<xsl:variable name="scheme" select="$context/ancestor-or-self::constraintSpec/@scheme"/>
<xsl:variable name="scheme" select="$context/ancestor-or-self::constraintSpec/@scheme|$context/ancestor-or-self::constraintDecl/@scheme"/>
<xsl:for-each select="$context">
<xsl:variable name="num">
<xsl:number level="any"/>
</xsl:variable>
<xsl:variable name="id">
<xsl:choose>
<xsl:when test="ancestor-or-self::*[@ident]">
<xsl:sequence select="ancestor-or-self::*[@ident][1]/@ident!translate( .,':','')"/>
</xsl:when>
<xsl:when test="ancestor-or-self::*[@xml:id]">
<xsl:sequence select="ancestor-or-self::*[@xml:id][1]/@xml:id!translate( .,':','')"/>
</xsl:when>
<xsl:when test="ancestor-or-self::constraintDecl">
<xsl:sequence select="'constraintDecl'"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:value-of
select="( $scheme,
'constraint',
ancestor-or-self::*[@ident]/@ident/translate( .,':',''),
$id,
$num )"
separator="-"/>
</xsl:for-each>
Expand Down
2 changes: 1 addition & 1 deletion odds/odd2odd.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ of this software, even if advised of the possibility of such damage.
<!-- … with any attributes the original <encodingDesc> (if any) had … -->
<xsl:apply-templates select="tei:encodingDesc/@*" mode="#current"/>
<!-- … and any content the original <encodingDesc> (if any) had; -->
<xsl:apply-templates select="tei:encodingDesc/node() except tei:constraintDecl" mode="pass0"/>
<xsl:apply-templates select="tei:encodingDesc/node() except //tei:constraintDecl" mode="pass0"/>
<!-- … then get the list of schemes to which the <constraintDecl>s apply … -->
<xsl:variable name="constraintDecl_schemes" select="$constraintDecls/@scheme" as="xs:string*"/>
<!-- … and for each such (unique) scheme … -->
Expand Down

0 comments on commit 2ff142b

Please sign in to comment.