diff --git a/CHANGELOG.md b/CHANGELOG.md
index dc2266f..b78fa14 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,4 @@
-# EFX Toolkit 2.0.0-alpha.2 Release Notes
+# EFX Toolkit 2.0.0-alpha.3 Release Notes
_The EFX Toolkit for Java developers is a library that enables the transpilation of [EFX](https://docs.ted.europa.eu/eforms/latest/efx) expressions and templates to different target languages. It also includes an implementation of an EFX-to-XPath transpiler._
@@ -6,16 +6,8 @@ _The EFX Toolkit for Java developers is a library that enables the transpilation
## In this release
-This release improves translation of EFX-1 templates as follows:
-
-- Renders sequences of labels when a sequence expression is used to provide asset-ids.
-- Renders distinct labels from sequences.
-- Improves date and time formatting.
-
-This release also includes a refactoring that moved XPath processing classes to the eForms Core Library 1.2.0 to improve reusability.
-
-There are no changes in EFX-2 translation included in this release.
-
+This release fixes an a bug that caused an exception to be thrown by XSLT processors when trying to format sequences of dates or times.
+This bug was reported by a user in [eForms Notice Viewer issue #88](https://github.com/OP-TED/eforms-notice-viewer/issues/88).
## EFX-1 Support
diff --git a/pom.xml b/pom.xml
index bfd0d30..d50786a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
eu.europa.ted.eforms
efx-toolkit-java
- 2.0.0-alpha.2
+ 2.0.0-alpha.3
jar
EFX Toolkit for Java
diff --git a/src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java b/src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java
index 9880486..1c3c1d0 100644
--- a/src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java
+++ b/src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java
@@ -29,8 +29,11 @@
import eu.europa.ted.efx.model.expressions.TypedExpression;
import eu.europa.ted.efx.model.expressions.path.PathExpression;
import eu.europa.ted.efx.model.expressions.path.StringPathExpression;
+import eu.europa.ted.efx.model.expressions.scalar.DateExpression;
import eu.europa.ted.efx.model.expressions.scalar.StringExpression;
+import eu.europa.ted.efx.model.expressions.sequence.DateSequenceExpression;
import eu.europa.ted.efx.model.expressions.sequence.StringSequenceExpression;
+import eu.europa.ted.efx.model.expressions.sequence.TimeSequenceExpression;
import eu.europa.ted.efx.model.templates.ContentBlock;
import eu.europa.ted.efx.model.templates.ContentBlockStack;
import eu.europa.ted.efx.model.templates.Markup;
@@ -496,9 +499,29 @@ public void exitStandardExpressionBlock(StandardExpressionBlockContext ctx) {
// functions.
if (TypedExpression.class.isAssignableFrom(expression.getClass())) {
if (EfxDataType.Date.class.isAssignableFrom(((TypedExpression) expression).getDataType())) {
- expression = new StringExpression("format-date(" + expression.getScript() + ", '[D01]/[M01]/[Y0001]')");
+
+ var loopVariable = new Variable("item",
+ this.script.composeVariableDeclaration("item", DateExpression.class), DateExpression.empty(),
+ this.script.composeVariableReference("item", DateExpression.class));
+
+ expression = this.script.composeForExpression(
+ this.script.composeIteratorList(
+ List.of(this.script.composeIteratorExpression(loopVariable.declarationExpression,
+ new DateSequenceExpression(expression.getScript())))),
+ new StringExpression("format-date($item, '[D01]/[M01]/[Y0001]')"),
+ StringSequenceExpression.class);
} else if (EfxDataType.Time.class.isAssignableFrom(((TypedExpression) expression).getDataType())) {
- expression = new StringExpression("format-time(" + expression.getScript() + ", '[H01]:[m01] [Z]')");
+
+ var loopVariable = new Variable("item",
+ this.script.composeVariableDeclaration("item", DateExpression.class), DateExpression.empty(),
+ this.script.composeVariableReference("item", DateExpression.class));
+
+ expression = this.script.composeForExpression(
+ this.script.composeIteratorList(
+ List.of(this.script.composeIteratorExpression(loopVariable.declarationExpression,
+ new TimeSequenceExpression(expression.getScript())))),
+ new StringExpression("format-time($item, '[H01]:[m01] [Z]')"),
+ StringSequenceExpression.class);
}
}
diff --git a/src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java b/src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java
index ccd9e19..8d87234 100644
--- a/src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java
+++ b/src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java
@@ -38,7 +38,9 @@
import eu.europa.ted.efx.model.expressions.scalar.ScalarExpression;
import eu.europa.ted.efx.model.expressions.scalar.StringExpression;
import eu.europa.ted.efx.model.expressions.scalar.TimeExpression;
+import eu.europa.ted.efx.model.expressions.sequence.DateSequenceExpression;
import eu.europa.ted.efx.model.expressions.sequence.StringSequenceExpression;
+import eu.europa.ted.efx.model.expressions.sequence.TimeSequenceExpression;
import eu.europa.ted.efx.model.templates.ContentBlock;
import eu.europa.ted.efx.model.templates.ContentBlockStack;
import eu.europa.ted.efx.model.templates.Markup;
@@ -559,9 +561,29 @@ public void exitStandardExpressionBlock(StandardExpressionBlockContext ctx) {
// functions.
if (TypedExpression.class.isAssignableFrom(expression.getClass())) {
if (EfxDataType.Date.class.isAssignableFrom(((TypedExpression) expression).getDataType())) {
- expression = new StringExpression("format-date(" + expression.getScript() + ", '[D01]/[M01]/[Y0001]')");
+
+ var loopVariable = new Variable("item",
+ this.script.composeVariableDeclaration("item", DateExpression.class), DateExpression.empty(),
+ this.script.composeVariableReference("item", DateExpression.class));
+
+ expression = this.script.composeForExpression(
+ this.script.composeIteratorList(
+ List.of(this.script.composeIteratorExpression(loopVariable.declarationExpression,
+ new DateSequenceExpression(expression.getScript())))),
+ new StringExpression("format-date($item, '[D01]/[M01]/[Y0001]')"),
+ StringSequenceExpression.class);
} else if (EfxDataType.Time.class.isAssignableFrom(((TypedExpression) expression).getDataType())) {
- expression = new StringExpression("format-time(" + expression.getScript() + ", '[H01]:[m01] [Z]')");
+
+ var loopVariable = new Variable("item",
+ this.script.composeVariableDeclaration("item", DateExpression.class), DateExpression.empty(),
+ this.script.composeVariableReference("item", DateExpression.class));
+
+ expression = this.script.composeForExpression(
+ this.script.composeIteratorList(
+ List.of(this.script.composeIteratorExpression(loopVariable.declarationExpression,
+ new TimeSequenceExpression(expression.getScript())))),
+ new StringExpression("format-time($item, '[H01]:[m01] [Z]')"),
+ StringSequenceExpression.class);
}
}
diff --git a/src/test/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1Test.java b/src/test/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1Test.java
index 4e2c45e..02153f6 100644
--- a/src/test/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1Test.java
+++ b/src/test/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1Test.java
@@ -353,11 +353,11 @@ void testEndOfLineComments() {
@Test
void testImplicitFormatting_Dates() {
- assertEquals("let block01() -> { eval(format-date(PathNode/StartDateField/xs:date(text()), '[D01]/[M01]/[Y0001]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartDate}"));
- }
+ assertEquals("let block01() -> { eval(for $item in PathNode/StartDateField/xs:date(text()) return format-date($item, '[D01]/[M01]/[Y0001]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartDate}"));
+ }
@Test
void testImplicitFormatting_Times() {
- assertEquals("let block01() -> { eval(format-time(PathNode/StartTimeField/xs:time(text()), '[H01]:[m01] [Z]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartTime}"));
- }
+ assertEquals("let block01() -> { eval(for $item in PathNode/StartTimeField/xs:time(text()) return format-time($item, '[H01]:[m01] [Z]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartTime}"));
+ }
}