TEIC / Stylesheets

TEI XSL Stylesheets
238 stars 126 forks source link

classSpec @‍generate is ignored in Pure ODD content model #582

Open dmj opened 2 years ago

dmj commented 2 years ago

Considere the following schema specification:

<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0"
     xmlns:rng="http://relaxng.org/ns/structure/1.0">
  <teiHeader>
    <fileDesc>
      <titleStmt>
        <title>Title</title>
      </titleStmt>
      <publicationStmt>
        <p>Publication Information</p>
      </publicationStmt>
      <sourceDesc>
        <p>Information about the source</p>
      </sourceDesc>
    </fileDesc>
  </teiHeader>
  <text>
    <body>
      <schemaSpec ident="schema" start="root">
        <elementSpec ident="root">
          <content>
            <classRef key="content" expand="alternation"/>
          </content>
        </elementSpec>
        <classSpec ident="content" type="model" generate="sequence"/>
        <elementSpec ident="element-1">
          <classes>
            <memberOf key="content"/>
          </classes>
          <content>
            <textNode/>
          </content>
        </elementSpec>
        <elementSpec ident="element-2">
          <classes>
            <memberOf key="content"/>
          </classes>
          <content>
            <textNode/>
          </content>
        </elementSpec>
      </schemaSpec>
    </body>
  </text>
</TEI>

The classRef in the root element's content model asks the transpiler to create an alternation of the class members ("any one member of the class may appear"), the classSpec on the other hand declares that the members of the class are to be provided in sequence.

From my understanding this should result in an error. The stylesheets (Version 4.4.0, Last updated on 19th April 2022, revision ff9cc28b0) seem to ignore the classSpec/@‍generate.

<?xml version="1.0" encoding="utf-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         xmlns:tei="http://www.tei-c.org/ns/1.0"
         xmlns:teix="http://www.tei-c.org/ns/Examples"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
         ns="http://www.tei-c.org/ns/1.0"><!--
Schema generated from ODD source 2022-10-21T11:51:55Z. .
TEI Edition: Version 4.4.0. Last updated on
        19th April 2022, revision ff9cc28b0
TEI Edition Location: https://www.tei-c.org/Vault/P5/Version 4.4.0/

--><!---->
   <sch:ns xmlns:sch="http://purl.oclc.org/dsdl/schematron"
           prefix="tei"
           uri="http://www.tei-c.org/ns/1.0"/>
   <define name="root">
      <element name="root">
         <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
         <choice>
            <ref name="element-1"/>
            <ref name="element-2"/>
         </choice>
      </element>
   </define>
   <define name="element-1">
      <element name="element-1">
         <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
         <text/>
      </element>
   </define>
   <define name="element-2">
      <element name="element-2">
         <a:documentation xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"/>
         <text/>
      </element>
   </define>
   <start>
      <choice>
         <ref name="root"/>
      </choice>
   </start>
</grammar>
ebeshero commented 2 years ago

Thanks @dmj! We should probably test the behavior of @generate on a sample ODD and its outputs in this context and see what we can do...It might not generate an error, but I'm also wondering under what conditions <classSpec> is ignored or overruled.

lb42 commented 2 years ago

I agree with you that this is an error which should be detected by the ODD processor

sydb commented 2 years ago

I have to admit, at the moment I am not sure I understand the reason for the existence of @generate of <classSpec>. Thus I am wondering (aloud) if we could just drop it, and thus avoid conflicts between it and @expand of <classRef>.

sydb commented 2 years ago

We are considering this blocked until we decide whether or not to keep @generate at all, or to have some constraint that would limit @expand to match @generate, or whatever, which should be discussed in TEI#2369.

sydb commented 1 year ago

I have been playing around with classes, @generate, and @expand for much of yesterday, and have discovered some horrifying (at least to me) things.

Remember as you read this that although @generate supposedly lists which values of the corresponding @expand are valid, the way that is currently done in our Stylesheets is only the patterns listed on @generate are generated (hence the mildly bizarre name of the attribute).

My take on all this is that

  1. Whether we drop @generate as useless, or keep it as an extra internal semantic check on an ODD, we need to fix the Stylesheets so that all 6 patterns are always generated unless we keep @generate and it explicitly says otherwise.
  2. This is pretty high priority, because it is blocking my work on TEI ticket 2214.

Note-to-self Commands used:


$ egrep '^model\.[A-Za-z0-9._-]+\s*=' Exemplars/tei_all.rnc | perl -pe 's,\s*=.*$,,; s,_.*$,,;' | rank | egrep ' 1 ' | sort | perl -pe 's,^\s+1 ,,;'  > /tmp/classes_only_1.txt
$ egrep '^model\.[A-Za-z0-9._-]+\s*=' Exemplars/tei_all.rnc | perl -pe 's,\s*=.*$,,; s,_.*$,,;' | rank | egrep ' 6 ' | sort | perl -pe 's,^\s+6 ,,;'  > /tmp/classes_all_6.txt
$ xsel -t -m "//t:classSpec[@type='model'][ not( t:classes ) ]" -v "@ident" -n p5subset.xml | sort > /tmp/classes_sans_classes.txt
$ xsel -t -m "//t:classSpec[@type='model'][ t:classes ]" -v "@ident" -n p5subset.xml | sort > /tmp/classes_with_classes.txt