Skip to content

Makros and if-conditionals #371

Open
@TobiasNx

Description

@TobiasNx

At the moment you cannot use makros in if-conditionals but also you also cannot create an makro that is only the if-conditional.

In context of lobid ressources - ALMA we needed to check for duplicates and wanted to reuse a small marko that we do not need to write the if-conditional again and again:

  <macro name="ignoreLocalExtensions">
      <if>
        <none flushWith="$[dsource][01] " sameEntity="true">
          <data name="" source="$[dsource][01] .M" />
        </none>
      </if>
  </macro>

That did not work with:

    <entity name="" flushWith="100[01] " sameEntity="true">
      <call-macro name="ignoreLocalExtensions" field="100" />
    ... 
    </entity> 

We received:

Caused by: org.xml.sax.SAXParseException; systemId: file:/home/tobias/git/lobid-resources/src/main/resources/alma/macros.xml; lineNumber: 159; columnNumber: 11; cvc-complex-type.2.4.a: Invalid content was found starting with element 'if'. One of '{"http://www.culturegraph.org/metamorph":group, "http://www.culturegraph.org/metamorph":data, "http://www.culturegraph.org/metamorph":all, "http://www.culturegraph.org/metamorph":any, "http://www.culturegraph.org/metamorph":choose, "http://www.culturegraph.org/metamorph":combine, "http://www.culturegraph.org/metamorph":concat, "http://www.culturegraph.org/metamorph":none, "http://www.culturegraph.org/metamorph":square, "http://www.culturegraph.org/metamorph":tuples, "http://www.culturegraph.org/metamorph":range, "http://www.culturegraph.org/metamorph":equalsFilter, "http://www.culturegraph.org/metamorph":containsFilter, "http://www.culturegraph.org/metamorph":entity}' is expected.

Then we tried to create a makro for the condition of the if-conditional:

  <macro name="ignoreLocalExtensions">
        <none flushWith="$[dsource][01] " sameEntity="true">
          <data name="" source="$[dsource][01] .M" />
        </none>
  </macro>

That did not work with:

    <entity name="" flushWith="100[01] " sameEntity="true">
        <if>
          <call-macro name="ignoreLocalExtensions" field="100" />
       </if>
    ... 
    </entity> 

We received:

Caused by: org.xml.sax.SAXParseException; systemId: file:/home/tobias/git/lobid-resources/src/main/resources/alma/common/contribution.xml; lineNumber: 12; columnNumber: 64; cvc-complex-type.2.4.a: Invalid content was found starting with element 'call-macro'. One of '{"http://www.culturegraph.org/metamorph":group, "http://www.culturegraph.org/metamorph":data, "http://www.culturegraph.org/metamorph":all, "http://www.culturegraph.org/metamorph":any, "http://www.culturegraph.org/metamorph":choose, "http://www.culturegraph.org/metamorph":combine, "http://www.culturegraph.org/metamorph":concat, "http://www.culturegraph.org/metamorph":none, "http://www.culturegraph.org/metamorph":square, "http://www.culturegraph.org/metamorph":tuples, "http://www.culturegraph.org/metamorph":range, "http://www.culturegraph.org/metamorph":equalsFilter, "http://www.culturegraph.org/metamorph":containsFilter}' is expected.

We discussed how easily implement at least one form of combining if-conditionals and makros.
At the moment it seems that the option to allow makros in an if-conditional as we tried in our second attempt seems to be the easiest.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions