Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

Gotchas in Eclipse JET (JET2)

No uniq()

There are no XPath functions to uniq the result of XPath (e.g. text element). If you want to uniq something, you have to implement control break with <c:iterate> like:

<c:setVariable select="''" var="control" />
<c:iterate select="XPath to list text elements" var="item" >
  <c:if test=“$item!=‘${$control}’”>
    DO SOMETHING WITH $item
    <c:setVariable select="${$item}" var="control" />
  </c:if>
</c:iterate> 

No String.join() equivalent

There are no XPath functions to join strings. You have to implement string join logic with <c:iterate> like:

<%-- join strings with "+" --%>
<c:setVariable select="''" var="control" />
<c:iterate select="XPath to list text elements" var="item" >
  <c:choose>
    <c:when test="$control=''">
      <c:setVariable select="string('X')" var="control" />
    </c:when>
    <c:otherwise>
      + 
    </c:otherwise>
  </c:choose>
  WRITE $item
</c:iterate> 

Can’t count numbers

There are no way to implement loop with index like for (int i=0; i<N; i++) in ordinal programming language. It would be better to implement loops in the generated Java source, rather than in JET templates.

Almost everything is XPath

<c:setVariable select="''" var="item" />

is OK. But

<c:setVariable select="'A'" var="item" />

will cause runtime error, because the content of value attribute is considered as XPath (there is no such a XML element in scope). You have to write like this:

<c:setVariable select="string('A')" var="item" />