erasmus-without-paper / ewp-specs-api-iias

Specifications of EWP's Interinstitutional Agreements API.
MIT License
4 stars 13 forks source link

XSLT produces invalid XML when the IIA-Get-Response contains more IIAs #159

Closed demilatof closed 7 months ago

demilatof commented 8 months ago

Thanks to @fioravanti-unibo 's notice, I have realized that there is a bug in the XSLTs, so that they produce invalid XML when the IIA-Get-Response contains more IIAs. The problem is that if we have more than one IIA the XSLT output lacks the root element. You can verify by yourself here https://www.w3schools.com/xml/xml_validator.asp If you put in the validator box the actual result of XSLT transformation:

<?xml version="1.0" encoding="UTF-8"?>
<iia>
   <iia-id>iia_id_1</iia-id>
   <text-to-hash>this is the text to hash for the first IIA</text-to-hash>
</iia>

you have no error; BUT if you add a second IIA to the XML produced by the XSLT

<?xml version="1.0" encoding="UTF-8"?>
<iia>
   <iia-id>iia_id_1</iia-id>
   <text-to-hash>this is the text to hash for the first IIA</text-to-hash>
</iia>
<iia>
   <iia-id>iia_id_2</iia-id>
   <text-to-hash>this is the text to hash for the second IIA</text-to-hash>
</iia>

The validation fails. The solution is easy, just adding a wrapping element, e.g. :

<?xml version="1.0" encoding="UTF-8"?>
<iia-processed>
   <iia>
      <iia-id>iia_id_1</iia-id>
      <text-to-hash>this is the text to hash for the first IIA</text-to-hash>
   </iia>
   <iia>
      <iia-id>iia_id_2</iia-id>
      <text-to-hash>this is the text to hash for the second IIA</text-to-hash>
   </iia>
</iia-processed>

The above code is correct for the W3C validator.

We can obtain a good XML just changing two lines in the XSLT. For the transform_version_7.xsl we can

And similar for transform_version_6.xsl

mkurzydlowski commented 8 months ago

Is that a problem that makes it impossible to parse the XSLT output or does it only occur when you try to validate the output?

fioravanti-unibo commented 8 months ago

Is that a problem that makes it impossible to parse the XSLT output or does it only occur when you try to validate the output?

To parse the document you have to pre-parse it with your preferred XML framework and this step fails: the document produced when there are multiple agreements is not well formed because it is missing a root element, so any parser will fail.

There is no XML schema, so technically you can't and shouldn't validate it.

mkurzydlowski commented 7 months ago

Please review the proposed change.

demilatof commented 7 months ago

Please review the proposed change.

It seems to me that now the two XSLTs produce good XML (I've tested them online). Thanks