<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
<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
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.