Logic to Find the position of last node in Responys EMD Version

47 Views Asked by At

<xsl:choose> <xsl:when test="position() != last()"> </xsl:when> </xsl:choose>

I am trying to use last() function in EMD Rpl function but that is not working

1

There are 1 best solutions below

0
On

I'm not sure how Responys EMD configures FreeMarker. Also I saw Oracle sometimes uses their own FreeMarker fork, which is possibly based on some really old version. But I will assume it works as usual/up-to-date FreeMarker, but maybe it doesn't.

While someElement['position()'] invokes the XPath function, it always returns -1 for some reason. But if you are listing elements with #list, you can use ?is_last, like this (using https://try.freemarker.apache.org syntax for the data model).

Data model:

doc=<root>
      <a>text 1</a>
      <a>text 2</a>
    </root>

Template:

<#list doc.root.a as a>
  ${a}
  <#if a?is_last>
    That was the last one.
  </#if>
</#list>

which prints:

text 1
text 2
  That was the last one.

(There are also other fancy features for doing things based on the position of an item related to #list, like #sep, but see FreeMarker documentation.)

Outside #list, if you just have the element from somewhere, myElement@@next_sibling_element[0]?? will return false for the last element.