diff --git a/src/main/java/eu/europa/ted/efx/xpath/XPathScriptGenerator.java b/src/main/java/eu/europa/ted/efx/xpath/XPathScriptGenerator.java index 83b3c82..2756258 100644 --- a/src/main/java/eu/europa/ted/efx/xpath/XPathScriptGenerator.java +++ b/src/main/java/eu/europa/ted/efx/xpath/XPathScriptGenerator.java @@ -83,10 +83,7 @@ public T composeFieldValueReference(PathExpression fieldR if ((MultilingualStringExpression.class.isAssignableFrom(type) || MultilingualStringListExpression.class.isAssignableFrom(type)) && !XPathContextualizer.hasPredicate(fieldReference, "@languageID")) { - PathExpression languageSpecific = XPathContextualizer.addPredicate(fieldReference, "@languageID=$__LANG__"); - String script = "(for $__LANG__ in $PREFERRED_LANGUAGES return " + languageSpecific.script - + "/normalize-space(text()), " + fieldReference.script + "/normalize-space(text()))[1]"; - return Expression.instantiate(script, type); + return Expression.instantiate("efx:preferred-language-text(" + fieldReference.script + ")", type); } if (StringExpression.class.isAssignableFrom(type) || StringListExpression.class.isAssignableFrom(type)) { return Expression.instantiate(fieldReference.script + "/normalize-space(text())", type); diff --git a/src/test/java/eu/europa/ted/efx/EfxExpressionTranslatorTest.java b/src/test/java/eu/europa/ted/efx/EfxExpressionTranslatorTest.java index 6fea719..6a95ef7 100644 --- a/src/test/java/eu/europa/ted/efx/EfxExpressionTranslatorTest.java +++ b/src/test/java/eu/europa/ted/efx/EfxExpressionTranslatorTest.java @@ -97,8 +97,8 @@ void testLikePatternCondition_WithNot() { @Test void testFieldValueComparison_UsingTextFields() { assertEquals( - "(for $__LANG__ in $PREFERRED_LANGUAGES return PathNode/TextMultilingualField[@languageID=$__LANG__]/normalize-space(text()), PathNode/TextMultilingualField/normalize-space(text()))[1]", - test("ND-Root", "BT-00-Text-Multilingual")); + "PathNode/TextField/normalize-space(text()) = efx:preferred-language-text(PathNode/TextMultilingualField)", + test("ND-Root", "BT-00-Text == BT-00-Text-Multilingual")); } @Test @@ -1076,6 +1076,18 @@ void testFieldReference_WithAxis() { test("ND-Root", "ND-Root::preceding::BT-00-Integer")); } + @Test + void testMultilingualTextFieldReference() { + assertEquals("efx:preferred-language-text(PathNode/TextMultilingualField)", + test("ND-Root", "BT-00-Text-Multilingual")); + } + + @Test + void testMultilingualTextFieldReference_WithLanguagePredicate() { + assertEquals("PathNode/TextMultilingualField[./@languageID = 'eng']/normalize-space(text())", + test("ND-Root", "BT-00-Text-Multilingual[BT-00-Text-Multilingual/@languageID == 'eng']")); + } + /*** Boolean functions ***/ @Test