OP-TED / efx-toolkit-java

This is an EFX translator written in Java. It supports multiple target languages. It includes an EFX expression translator to XPath. It is used to in the generation of the Schematron rules in the eForms SDK.
European Union Public License 1.2
9 stars 1 forks source link

[1.3.0] XPathContextualizer leaves context when child with predicate has same EFX-Context as Parent #99

Closed JulianMa closed 8 months ago

JulianMa commented 10 months ago

The Patches for eForms SDK 1.7.2 introduced a new EFX Semantic, which uses the same context in child elements as their parent do. This in turn triggers a Bug inside the XPathContextualizer, which will then leave the childs context and instead select all children.

Given the following section of the template view-template/16.efx:

0 {ND-Organization} #{auxiliary|text|roles}: // Roles of this organisation
            0 {ND-Organization[count(for text:$orgid in OPT-200-Organization-Company return OPT-300-Procedure-Buyer[OPT-300-Procedure-Buyer == $orgid])>0]} #{auxiliary|text|buyer} // This org is a Buyer
                {OPP-050-Organization[OPP-050-Organization == TRUE]} #{field|name|OPP-050-Organization} // Leader of the group
                {OPP-052-Organization[OPP-052-Organization == TRUE]} #{field|name|OPP-052-Organization} // CPB Acquiring
                {OPP-051-Organization[OPP-051-Organization == TRUE]} #{field|name|OPP-051-Organization} // CPB Awarding
            {ND-Organization[(some text:$esender in (for text:$orgid in OPT-200-Organization-Company, text:$servprovtype in OPT-030-Procedure-SProvider[OPT-300-Procedure-SProvider == $orgid] return $servprovtype) satisfies $esender == 'serv-prov') or (some text:$esender1 in (for text:$tpoid in OPT-201-Organization-TouchPoint, text:$servprovtype1 in OPT-030-Procedure-SProvider[OPT-300-Procedure-SProvider == $tpoid] return $servprovtype1) satisfies $esender1 == 'serv-prov')]} #{auxiliary|text|organisation-providing-procurement-service} // This org is a Service Provider
            {ND-Organization[(some text:$esender in (for text:$orgid in OPT-200-Organization-Company, text:$servprovtype in OPT-030-Procedure-SProvider[OPT-300-Procedure-SProvider == $orgid] return $servprovtype) satisfies $esender == 'ted-esen') or (some text:$esender1 in (for text:$tpoid in OPT-201-Organization-TouchPoint, text:$servprovtype1 in OPT-030-Procedure-SProvider[OPT-300-Procedure-SProvider == $tpoid] return $servprovtype1) satisfies $esender1 == 'ted-esen')]} #{auxiliary|text|organisation-esender} // This org is an eSender
            {ND-Organization[(OPT-200-Organization-Company == OPT-301-Lot-AddInfo) or (OPT-201-Organization-TouchPoint == OPT-301-Lot-AddInfo)]} #{auxiliary|text|organisation-providing-info-procedure} // Additional Information Providing Organisation (LOT)

Will result in a .xsl of: (which can be reproduced when using f.e. the eforms-notice-viewer in Version 1.8.0, which is the last version supporting EFX 1.0)

 <xsl:template name="block050118"> 
        <section title="block050118"> 
            <span class="label">
                <xsl:value-of select="($labels//entry[@key=concat('auxiliary', '|', 'text', '|', 'roles')]/text(), concat('{', concat('auxiliary', '|', 'text', '|', 'roles'), '}'))[1]"/>
            </span>
            <span class="text">
                <xsl:text>:</xsl:text>
            </span>  
            <xsl:for-each select="../efac:Organization[count(for $orgid in efac:Company/cac:PartyIdentification/cbc:ID/normalize-space(text()) return ../../../../../../cac:ContractingParty/cac:Party/cac:PartyIdentification/cbc:ID[./normalize-space(text()) = $orgid]/normalize-space(text())) &gt; 0]"> 
                <xsl:call-template name="block05011801"/> 
            </xsl:for-each>  
            <xsl:for-each select="../efac:Organization[(some $esender in (for $orgid in efac:Company/cac:PartyIdentification/cbc:ID/normalize-space(text()), $servprovtype in ../../../../../../cac:ContractingParty/cac:Party/cac:ServiceProviderParty/cbc:ServiceTypeCode[../cac:Party/cac:PartyIdentification/cbc:ID/normalize-space(text()) = $orgid]/normalize-space(text()) return $servprovtype) satisfies $esender = 'serv-prov') or (some $esender1 in (for $tpoid in efac:TouchPoint/cac:PartyIdentification/cbc:ID/normalize-space(text()), $servprovtype1 in ../../../../../../cac:ContractingParty/cac:Party/cac:ServiceProviderParty/cbc:ServiceTypeCode[../cac:Party/cac:PartyIdentification/cbc:ID/normalize-space(text()) = $tpoid]/normalize-space(text()) return $servprovtype1) satisfies $esender1 = 'serv-prov')]"> 
                <xsl:call-template name="block05011802"/> 
            </xsl:for-each>  
            <xsl:for-each select="../efac:Organization[(some $esender in (for $orgid in efac:Company/cac:PartyIdentification/cbc:ID/normalize-space(text()), $servprovtype in ../../../../../../cac:ContractingParty/cac:Party/cac:ServiceProviderParty/cbc:ServiceTypeCode[../cac:Party/cac:PartyIdentification/cbc:ID/normalize-space(text()) = $orgid]/normalize-space(text()) return $servprovtype) satisfies $esender = 'ted-esen') or (some $esender1 in (for $tpoid in efac:TouchPoint/cac:PartyIdentification/cbc:ID/normalize-space(text()), $servprovtype1 in ../../../../../../cac:ContractingParty/cac:Party/cac:ServiceProviderParty/cbc:ServiceTypeCode[../cac:Party/cac:PartyIdentification/cbc:ID/normalize-space(text()) = $tpoid]/normalize-space(text()) return $servprovtype1) satisfies $esender1 = 'ted-esen')]"> 
                <xsl:call-template name="block05011803"/> 
            </xsl:for-each>  
            <xsl:for-each select="../efac:Organization[(efac:Company/cac:PartyIdentification/cbc:ID/normalize-space(text()) = ../../../../../../cac:ProcurementProjectLot[cbc:ID/@schemeName='Lot']/cac:TenderingTerms/cac:AdditionalInformationParty/cac:PartyIdentification/cbc:ID/normalize-space(text())) or (efac:TouchPoint/cac:PartyIdentification/cbc:ID/normalize-space(text()) = ../../../../../../cac:ProcurementProjectLot[cbc:ID/@schemeName='Lot']/cac:TenderingTerms/cac:AdditionalInformationParty/cac:PartyIdentification/cbc:ID/normalize-space(text()))]"> 
                <xsl:call-template name="block05011804"/> 
....
        </section> 
    </xsl:template> 

Because of a Bug inside the XPathContextualizer, the generated XPath will leave the block's context: <xsl:for-each select="../efac:Organization[count(for $orgid in...]... In this case, it should be : <xsl:for-each select=".[count(for $orgid in...]...

Which in turn will break the selector, because all children of the parent element will be selected, instead of the current one.

This has been corrected with commit 2d43d81b8d7a1f5948ca3c318c74b64aa5cea32d, however this fix is only available inside the 2.0.0 alpha releases, which we can't use yet. Right now, all view-templates are broken because of this Bug.

Are there any plans, to release a 1.3.1 Version of the efx-toolkit, to fix this behaviour?

rousso commented 8 months ago

Hi @JulianMa,

EFX Toolkit 1.3.0 is not being maintained. You should use the latest EFX Toolkit 2.0.0 (currently the latest release is EFX Toolkit 2.0.0-alpha.2; alpha.3 is coming in the next days).

Although technically the EF Toolkit 2.0.0 is in alpha version (and it is normal if you don't consider it for production use), in practice, the support that EFX Toolkit 2.0.0 provides for EFX 1 is stable and it contains our latest updates and fixes.

In other words, the EFX Toolkit supports both EFX 1 and EFX 2 (the next version of EFX that will be released with SDK 2.0.0). You can consider the EFX Toolkit 2 as stable if you are using it for EFX 1 (which is true for everyone). EFX 2 on the other hand, is work in progress, hence the "alpha" level versioning of the toolkit. Our own viewer in production uses EFX Toolkit 2.0.0-alpha too.

The reason we are not updating EFX Toolkit 1.x.x anymore is because to support both EFX 2 and EFX 1 we needed to make significant changes in the interfaces (API) that we are using internally so it is not practical (or even possible) to maintain two very different code bases.

I did not investigate the actual issue you that are reporting because you are associating it with EFX Toolkit 1.3.0. Please try EFX Toolkit 2.0.0-alpha.2 and if the issue persists then you are welcome to re-open this issue.

Thank you for your understanding, Yannis