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

Modifying annotations does not work when.... #216

Open
nquenouille opened this issue Feb 28, 2024 · 0 comments
Open

Modifying annotations does not work when.... #216

nquenouille opened this issue Feb 28, 2024 · 0 comments

Comments

@nquenouille
Copy link

nquenouille commented Feb 28, 2024

  • ... it is an abbreviation (no modification possible at all)
  • ... the tag has more than one attribute AND the attributes in question are used in other tags as well

What works:
Multiple unique attributes

annotate.html

<div class="annotation-form date">
      <paper-input name="when" label="when" type="date"/>
      <paper-input name="from" label="from" type="date"/>
      <paper-input name="to" label="to" type="date"/>
      <paper-input name="notBefore" label="notBefore" type="date"/>
      <paper-input name="notAfter" label="notAfter" type="date"/>
</div> 

annotation-config.xqm

case "date" return
      <date xmlns="http://www.tei-c.org/ns/1.0">
      {
          for $prop in map:keys($properties)[. = ('when', 'from', 'to', 'notBefore', 'notAfter')]
          return
              attribute { $prop } { $properties($prop) },
          $content()
      }
      </date>

One attribute, even if its key is a key to attributes in other tags as well ("target" is used as attribute in other tags as well)

annotate.html

<div class="annotation-form ref" data-i18n="[label]annotations.reference">
       <paper-input id="ref" name="target" label="target"/>
</div>

annotation-config.xqm

case "ref" return
   <ref xmlns="http://www.tei-c.org/ns/1.0" target="{$properties?target}">{$content()}</ref>

What does not work:

With only the "expan" attribute or two attributes (like "expan" and "type") - it does not matter, it does not work at all
annotate.html

<div class="annotation-form abbreviation" data-i18n="[label]annotations.abbreviation">
      <paper-input name="expan" data-i18n="[label]annotations.expansion" label="Expansion"/>
      <paper-input name="type" data-i18n="[label]annotations.type" label="Type"/>
</div>

annotation-config.xqm

case "abbreviation" return
      <choice xmlns="http://www.tei-c.org/ns/1.0">
          <abbr>
                {
                for $prop in map:keys($properties)[. = ('type')]
                return
                    attribute { $prop } { $properties($prop) },
                $content()
            }
         </abbr><expan>{$properties?expan}</expan>
      </choice>

With two attributes AND attributes where the key name is used elsewhere as well (like the "type" or "target" attribute)

annotate.html

<div class="annotation-form rs" data-i18n="[label]annotations.rs">
      <paper-input name="type" label="Type" />
      <paper-input name="key" label="Key" />
</div>

annotation-config.xqm

case "rs" return
    <rs xmlns="http://www.tei-c.org/ns/1.0" type="{$properties?type}" key="{$properties?key}">{$content()}
    </rs>

annotate.html

<div class="annotation-form gloss" data-i18n="[label]annotations.gloss">
      <paper-input name="target" label="Target-Id"/>
      <paper-input name="type" label="Type"/>
</div>

annotation-config.xqm

case "gloss" return
    <gloss xmlns="http://www.tei-c.org/ns/1.0">
        {
        for $prop in map:keys($properties)[. = ('target', 'type')]
        return
            attribute { $prop } { $properties($prop) },
        $content()
    }
    </gloss>

Curiosum:

<div class="annotation-form term" data-i18n="[label]annotations.term">
     <paper-input name="xmlid" label="xml:id" />
</div>

The "curiosum" (where I had to omit the colon in attribute xml:id) shows that in the anno:modify function (annotations.xql) the $key is taken from the name of the text-input field in annotate.html (see above), but not from the hard coded tag in annotation-config.xqm (and yes, I use term as a simple tag, not with the register):

annotation-config.xqm

case "term" return
     <term xmlns="http://www.tei-c.org/ns/1.0" xml:id="{$properties?xmlid}">{$content()}</term>

annotations.xql

case element() return
        if ($node is $target) then
            element { node-name($node) } {
                map:for-each($annotation?properties, function($key, $value) {
                    if ($value != '') then
                        attribute { $key } { $value }
                    else
                        ()
                }),
                anno:modify($node/node(), $target, $annotation)
            }
        else
            element { node-name($node) } {
                $node/@*,
                anno:modify($node/node(), $target, $annotation)
            }

I hope, I could explain it well. If not, feel free to ask.
Please, could anyone help here to get this right? I made my first steps in xQuery only last year in October, and I do not have the experience to change the lib code (and do not want to change it, since it is a library that gets updated with new versions).

Many thanks in advance!!!

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

No branches or pull requests

1 participant