Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ODD to Schematron conversion outputs only QuickFixes, no patterns #702

Closed
jjarosch opened this issue Oct 8, 2024 · 10 comments
Closed

ODD to Schematron conversion outputs only QuickFixes, no patterns #702

jjarosch opened this issue Oct 8, 2024 · 10 comments
Assignees

Comments

@jjarosch
Copy link

jjarosch commented Oct 8, 2024

As the title says, the generated file entirely skips the patterns and only includes the quick fixes. Vaguely, this seems to point to this section being the cause or involved:

<xsl:if test="key('CONSTRAINTs',1)">
<xsl:call-template name="blockComment">
<xsl:with-param name="content" select="'constraints:'"/>
</xsl:call-template>
</xsl:if>
<xsl:for-each select="key('CONSTRAINTs',1)">
<xsl:choose>
<xsl:when test="not( lang( $lang ) )"/>
<xsl:otherwise>
<xsl:variable name="patID" select="tei:makePatternID(.)"/>
<xsl:choose>
<xsl:when test="sch:pattern">
<!-- 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">
<!-- 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">
<!-- 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. -->
<pattern id="{$patID}">
<rule context="{tei:generate-context(.)}">
<xsl:apply-templates select="node()"/>
</rule>
</pattern>
</xsl:when>
<xsl: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()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>

Using TEI Garage, we get patterns (but no quick fixes) out of the same ODD. I understand TEI Garage uses this stylesheet: https://github.com/TEIC/Stylesheets/blob/dev/odds/extract-sch.xsl

Am I doing something wrong? Are there command line parameters to pass to extract-isosch.xsl?

@jjarosch jjarosch changed the title ODD to Schematron conversion includes only QuickFixes, no patterns ODD to Schematron conversion outputs only QuickFixes, no patterns Oct 8, 2024
@sydb
Copy link
Member

sydb commented Oct 19, 2024

Thanks for the report. After poking a little, it seems like extract-isosch.xsl is doing the right thing — there are no patterns in English (they are in German), and by default (perhaps somewhat inappropriately) it looks for English. BUT when I specify German as the desired language saxon -xsl:odds/extract-isosch.xsl -s:tei_bkd.odd lang=de > /tmp/tei_bkd.isosch seems to work fine, but bin/teitoschematron --lang=de --odd tei_bkd.odd /tmp/tei_bkd.isosch still fails to process the constraints!
Looking into it now, but I suspect I will have to go before I figure this out today. (It is not a problem with the shell script, it is sending the de to the ant just fine.)

P.S. Note that we do not expect extract-isosch.xsl to work entirely properly directly on tei_bkd.odd as I tried above, it is intended to be run on the “compiled” ODD generated from tei_bkd.odd + P5.

@sydb
Copy link
Member

sydb commented Oct 19, 2024

So it looks to me at first blush like processed (or “compiled”) ODD is being created correctly, but the language is not being passed on to profiles/default/schematron/to.xsl when it is invoked. In turn, I am not sure it would pass the $lang on to extract-isosch.xsl even if it had it.

OK. After poking around a bit more it looks like adding

      <param name="lang" expression="${lang}" if="lang"/>

to the call to XSLT/trax in profiles/default/schematron/to.xsl (~line 31) fixes the problem and allows the language de to passed in appropriately.

So that would seem to be the immediate fix to this problem. (Any chance you can test that, @jjarosch? I will try to test it more and make a PR later this weekend.) But it still strikes me that if every <constraint> is in German the routine ought to be smart enough to look for German by default. (Or at least generate a warning message, maybe?)

@jjarosch
Copy link
Author

I’m not entirely sure I follow. When I change https://github.com/TEIC/Stylesheets/blob/dev/profiles/default/schematron/to.xsl like this:

<xsl:stylesheet 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="3.0">
   <param name="lang" expression="${lang}" if="lang"/>
    <!-- import base conversion style -->
    <xsl:import href="../../../odds/extract-isosch.xsl"/>

  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">

– nothing changes. But is that what you meant in the first place?

Regarding general behaviour:

A message like “No language set, defaulting to en” might be a simple first prompt for users to realise that the lang parameter is needed. The slightly more elaborate thing to display might be “no constraints matching the selected language (en) found”.

A second thing that stands out to me is that the quick fixes are not checked for their language.

@sydb
Copy link
Member

sydb commented Oct 21, 2024

Sorry, that was my fault, I listed the wrong file for the <param> addition. Should have been schematron/build-to.xml, roughly line 31.

Yeah, I think your version of the message is mildly better, but we can worry about detailed wording later. The bigger question is whether we should presume that if there is no identifiable language for any constraints, they are all in English.

… the quick fixes are not checked for their language.

Oh bloody BLEEP, you are absolutely right. I will be gone most of today (doctor’s appointment) but hope to work on this ticket a bit tonight.

@jjarosch
Copy link
Author

Aah, yes, thanks, there’s the trax you mentioned. This

    <xslt processor="trax" force="yes" style="${profiledir}/${profile}/schematron/to.xsl" in="${inputFile}.processedodd" out="${outputFile}">
      <factory name="net.sf.saxon.TransformerFactoryImpl"/>
      <param name="lang" expression="${lang}" if="lang"/>
    </xslt>

works for me – it generates a lot of constraints and the schema file works!

Will the lang parameter also be needed for the notodd target in lines 35–39?

@sydb
Copy link
Member

sydb commented Oct 21, 2024

Oh, not sure.
Gotta go now, but will try to take a look in ~6 hours, give or take a few, when I get back to this. (Plan to change all those keys to be based on lang, not '1'. That should do the trick. :-)

@jjarosch
Copy link
Author

There’s no hurry on my end! Good luck at your appointment, and thanks again!

@sydb sydb self-assigned this Oct 24, 2024
@sydb sydb added this to the Release 7.58.0 milestone Oct 24, 2024
sydb added a commit that referenced this issue Oct 24, 2024
 to XSL, and re-work how languages and Schematron Quick Fixes are handled in extract-isosch.xsl.
@sydb
Copy link
Member

sydb commented Oct 25, 2024

@jjarosch — If you are up to it please checkout the sydb_702_extract_schematron branch and test your ODD there. (And feel free to comment on the PR (#704) rather than here, if that seems to make more sense.)

@jjarosch
Copy link
Author

It’s all looking good, it does what I expect. My colleague who wrote most of the schematron rules in our ODD had a look as well and didn’t spot any ‘semantic’ problems from the transformation.

So this patch will resolve my issue. Thanks again!!

@HelenaSabel
Copy link
Member

HelenaSabel commented Oct 29, 2024

Fixed via #704. Please be aware of TEIC/TEI#2608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants