Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
JET FAQ What are the JET whitespace handling rules?
Question
Does JET do anything to remove whitespace (and particularly new lines) from a template? Sometimes I get unwanted new lines in my template results, and sometimes I do not. It seems very unpredictable.
Answer
JET does have rules for removing new lines from the template results. Here they are:
1) JET will only CONSIDER removing whitespace if a language element (scriptlet, expression, declaration, directive, open tag, end tag, empty tag, comment) is 'alone' on a line. Technically, this is implemented as the element starts on a line in which preceding text in only whitespace, and ends on a line that is only whitespace. So, for example, the following are all 'alone' on a line:
<c:iterate select="..." var="..."> <%-- this is a multiline comment, but it is still 'alone' on a line --%>
2) For scriptlets, declarations, directives and comments, being alone on a line will cause JET to remove the surrounding whitespace, including new-line characters at the end of the trailing line.
3) For JET custom tags, which space removal is dependent on that tag. Each tag is declared with a 'whenContainingLineIsEmpty' attribute, which can have a value of either 'preserve' or 'remove'. Typically, tags that produce content preserve, while those that provide control structure like capabilities remove. Some examples of whitespace preserving tags: c:get, f:lc (lowercase). Examples of whitespace removing tags: c:iterate, c:if, c:include.
Back to the M2T-JET-FAQ