Skip to main content

REL Standard Tag Library

The RSTL is a library of REL tags providing standard functionality such as iterating collections, conditionals, imports, assignments, XML XSLT transformations, formatting dates, etc.

RSTL distributable is available on my Google Code page under REL Standard Tag Library. Always use the latest JAR.

This post describes each RSTL tag in the library explaining its functionality, attributes and providing examples. For understanding the way expressions are evaluated, please read my post about the Expression Language used by REL Standard Tag Library.

<c:choose> / <c:when> / <c:otherwise>

Syntax:
    <c:choose>
        <c:when test="expr1">
            Do something
        </c:when>
        <c:when test="expr2">
            Do something else
        </c:when>
        <c:otherwise>
            Do something otherwise
        </c:otherwise>
    </c:choose>

Attributes:
  • test : conditional expression;
Description:

This is the classic switch (if/else) conditional tag construct. A <c:choose> tag contains some <c:when> tags and at most one <c:otherwise> tag.

The test attribute expression is evaluated for each when tag, and for the first one that evaluates to true, its body is evaluated and included in the output. If none of the when tags evaluate to true, the otherwise tag body is evaluated and included in the output.

Example (simple if/else):
    <c:choose>
        <c:when test="userName == 'Mihai'">
            Hello, Mihai!
        </c:when>
        <c:otherwise>
            Hello, guest!
        </c:otherwise>
    </c:choose>

<c:forEach>

Syntax:
    <c:forEach var="expr" items="expr">
        Do something
    </c:forEach>

Attributes:
  • var : variable name or ${expression};
  • items : variable or expression evaluating to array of Object or java.util.List;
Description:

The tag executes the tag body for each item in the collection referenced by the items attribute. The current item in the iteration is stored temporarily (only for the duration of the loop) in the TransformContext under the name given by attribute var.

Example:
    <c:forEach var="cpMeta" items="pageMeta.componentPresentationMetas">
        <c:out value="cpMeta.componentId"/>
    </c:forEach>

<c:if>

Syntax:
    <c:if test="expr">
        Do something
    </c:if>

Attributes:
  • test : conditional expression;
Description:

The tag executes the tag body, if the attribute test evaluates to true.

Example:
    <c:if test="userName == 'Mihai'">
        Hello, Mihai!
    </c:if>

<c:import>

Syntax:
    <c:import var="expr" url="expr" componentTemplate="expr">
        <c:param name="expr" value="expr"/>
    </c:import>

Attributes:
  • var : variable name or ${expression};
  • url : tcmuri or string or ${expression};
  • componentTemplate : tcmuri or integer or ${expression};
  • name : string or ${expression};
  • value : string or ${expression};
Description:

The tag accesses the resource identified by attribute url and retrieves a its content. If a var is specified, it stores this content in the TransformContext under that name. The url can be either a string identifying a relative or fully qualified URL, a tcmuri of a Page, or a tcmuri of a Component. If url identifies a Component, then the attribute componentTemplate is used to read the Component Presentation on that Component. If componentTemplate is not specified in this case, the Component Presentation with highest priority is retrieved.

If any c:param tags are specified, their name and value attributes are used in the invocation of the url as query string or rendering parameters.

Example:
    <c:import var="xml" url="tcm:1-23-64">
        <c:param name="color" value="${myColor}"/>
    </c:import>


<c:out>

Syntax:
    <c:out value="expr"/>

Attributes:
  • value : variable or expression;
Description:

The tag outputs the evaluated value of the attribute var.

Example:
    <c:out value="cp.componentId"/>


<c:remove>

Syntax:
    <c:remove var="expr"/>

Attributes:
  • var : variable name or ${expression};
Description:

The tag removes the variable named by attribute var from the TransformContext.

Example:
    <c:remove var="cpList"/>

<c:set>

Syntax:
    <c:set var="expr" value="expr"/>
or
    <c:set var="expr">
        Do something
    </c:set>

Attributes:
  • var : variable name or ${expression};
  • value : value to set or ${expression};
Description:

The tag sets a variable named by attribute var in the TransformContext. The stored value is the result of evaluating attribute value, if specified; otherwise, it is the value of the tag body.

Example:
    <c:set var="user-name" value="${user + 'Account'}"/> 

<fmt:formatDate>

Syntax:
    <fmt:formatDate var="expr" value="expr" pattern="expr"/>

Attributes:
  • var : variable name or ${expression};
  • value : expression evaluating to java.util.Date object;
  • pattern : format pattern or ${expression};
Description:

The tag formats a java.util.Date specified by attribute value according to the pattern specified by attribute pattern. If an attribute var is specified, then the formatted date is stored as string entry in the TransformContext; otherwise, the formatted string is output.

Example:
    <fmt:formatDate value="myDate" pattern="dd.MM.yyyy HH:mm"/>

<fmt:parseDate>

Syntax:
    <fmt:parseDate var="expr" value="expr" pattern="expr"/>

Attributes:
  • var : variable name or ${expression};
  • value : String representing a date or ${expression};
  • pattern : format pattern or ${expression};
Description:

The tag parses a String represetation of a date specified in attribute value, in the format described by attribute pattern, and stores a java.util.Date in TransformContext under variable name specified in attribute var.

Example:
    <fmt:parseDate var="myDate" value="2013-07-23" pattern="yyyy-MM-dd"/>

<x:transform>

Syntax:
    <x:transform var="expr" doc="expr" xslt="expr">
        <x:param var="expr" select="expr" />
    </x:transform>

Attributes:
  • var : variable name or ${expression};
  • doc : expression evaluating to either string representing XML, org.w3c.dom.Document object or javax.xml.transform.dom.DOMSource object;
  • xslt : expression evaluating to either string representing XSLT or javax.xml.transform.Templates object;
  • select : string or ${expression} evaluating to Object;
Description:

The tag transforms the XML referred by attribute doc with the XSLT referred by attribute xslt. If attribute var is specified, the result is stored in TransformContext under the given name; otherwise, the result is output.

If any x:param tags are specified, their attributes var and select are used as transformation parameters.

Example:
    <x:transform doc="nav-xml" xslt="top-xslt">
        <x:param var="color" select="${bg-color}"/>
    </x:transform>


Comments

Peter Joles said…
I just watch your community webinar about your RSTL implementation - http://goo.gl/pRavCU . Very impressive work! I'm glad you stuck with the JSTL Standard tag library naming convention for the tags because it makes it very familiar for me. I haven't yet looked at how you implemented your parser but am interested in knowing if you used an base framework to build upon? I tried to find a JSTL parser out there that can be run outside of a servlet container but came short. I see some people suggest running an embedded Tomcat or Jetty server such that they can parse and process JSTL code. Another library looks to be able to do this but doesn't have the taglib support you seem to have implemented was Jxp http://jxp.sourceforge.net/ .
Mihai Cădariu said…
I took an existing parser (CogPar from cogitolearning.co.uk) and I modified it to plug in my own grammar. You can have a look at the link below and you'll see the actual implementation. It's really a classic LL(1) top-down parser, then of course combined with a substitution engine to traverse and resolve expression trees. It's all pretty much stand alone and I only make use of the REL context when I need to pass-in an object or some value from the context... so no craziness with embedding Tomcat/Jetty. I have no experience with JXP.

Link to the actual parser implementation code: https://code.google.com/p/yet-another-tridion-blog/source/browse/trunk/REL+Standard+Tag+Library/#REL%20Standard%20Tag%20Library%2Fsrc%2Fnet%2Fmitza%2Frel%2Fparser

Popular posts from this blog

Toolkit - Dynamic Content Queries

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post presents the Dynamic Content Query capability. The requirements for the Toolkit API are that it should be able to provide CustomMeta queries, pagination, and sorting -- all on the file system, without the use third party tools (database, search engines, indexers, etc). Therefore I had to implement a simple database engine and indexer -- which is described in more detail in post Writing My Own Database Engine . The querying logic does not make use of cache. This means the query logic is executed every time. When models are requested, the models are however retrieved using the ModelFactory and those are cached. Query Class This is the main class for dynamic content queries. It is the entry point into the execution logic of a query. The class takes as parameter a Criterion (presented below) which triggers the execution of query in all sub-criteria of a Criterio

A DD4T.net Implementation - Custom Binary Publisher

The default way to publish binaries in DD4T is implemented in class DD4T.Templates.Base.Utils.BinaryPublisher and uses method RenderedItem.AddBinary(Component) . This produces binaries that have their TCM URI as suffix in their filename. In my recent project, we had a requirement that binary file names should be clean (without the TCM URI suffix). Therefore, it was time to modify the way DD4T was publishing binaries. The method in charge with publishing binaries is called PublishItem and is defined in class BinaryPublisher . I therefore extended the BinaryPublisher and overrode method PublishItem. public class CustomBinaryPublisher : BinaryPublisher { private Template currentTemplate; private TcmUri structureGroupUri; In its simplest form, method PublishItem just takes the item and passes it to the AddBinary. In order to accomplish the requirement, we must specify a filename while publishing. This is the file name part of the binary path of Component.BinaryConten

Scaling Policies

This post is part of a bigger topic Autoscaling Publishers in AWS . In a previous post we talked about the Auto Scaling Groups , but we didn't go into details on the Scaling Policies. This is the purpose of this blog post. As defined earlier, the Scaling Policies define the rules according to which the group size is increased or decreased. These rules are based on instance metrics (e.g. CPU), CloudWatch custom metrics, or even CloudWatch alarms and their states and values. We defined a Scaling Policy with Steps, called 'increase_group_size', which is triggered first by the CloudWatch Alarm 'Publish_Alarm' defined earlier. Also depending on the size of the monitored CloudWatch custom metric 'Waiting for Publish', the Scaling Policy with Steps can add a difference number of instances to the group. The scaling policy sets the number of instances in group to 1 if there are between 1000 and 2000 items Waiting for Publish in the queue. It also sets the