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

Running sp_updatestats on AWS RDS database

Part of the maintenance tasks that I perform on a MSSQL Content Manager database is to run stored procedure sp_updatestats . exec sp_updatestats However, that is not supported on an AWS RDS instance. The error message below indicates that only the sa  account can perform this: Msg 15247 , Level 16 , State 1 , Procedure sp_updatestats, Line 15 [Batch Start Line 0 ] User does not have permission to perform this action. Instead there are several posts that suggest using UPDATE STATISTICS instead: https://dba.stackexchange.com/questions/145982/sp-updatestats-vs-update-statistics I stumbled upon the following post from 2008 (!!!), https://social.msdn.microsoft.com/Forums/sqlserver/en-US/186e3db0-fe37-4c31-b017-8e7c24d19697/spupdatestats-fails-to-run-with-permission-error-under-dbopriveleged-user , which describes a way to wrap the call to sp_updatestats and execute it under a different user: create procedure dbo.sp_updstats with execute as 'dbo' as

Content Delivery Monitoring in AWS with CloudWatch

This post describes a way of monitoring a Tridion 9 combined Deployer by sending the health checks into a custom metric in CloudWatch in AWS. The same approach can also be used for other Content Delivery services. Once the metric is available in CloudWatch, we can create alarms in case the service errors out or becomes unresponsive. The overall architecture is as follows: Content Delivery service sends heartbeat (or exposes HTTP endpoint) for monitoring Monitoring Agent checks heartbeat (or HTTP health check) regularly and stores health state AWS lambda function: runs regularly reads the health state from Monitoring Agent pushes custom metrics into CloudWatch I am running the Deployer ( installation docs ) and Monitoring Agent ( installation docs ) on a t2.medium EC2 instance running CentOS on which I also installed the Systems Manager Agent (SSM Agent) ( installation docs ). In my case I have a combined Deployer that I want to monitor. This consists of an Endpoint and a

Debugging a Tridion 2011 Event System

OK, so you wrote your Tridion Event System. Now it's time to debug it. I know this is a hypothetical situtation -- your code never needs any kind of debugging ;) but indulge me... Recently, Alvin Reyes ( @nivlong ) blogged about being difficult to know how exactly to debug a Tridion Event System. More exactly, the question was " What process do I attach to for debugging even system code? ". Unfortunately, there is no simple or generic answer for it. Different events are fired by different Tridion CM modules. These modules run as different programs (or services) or run inside other programs (e.g. IIS). This means that you will need to monitor (or debug) different processes, based on which events your code handles. So the usual suspects are: dllhost.exe (or dllhost3g.exe ) - running as the MTSUser is the SDL Tridion Content Manager COM+ application and it fires events on generic TOM objects (e.g. events based on Tridion.ContentManager.Extensibility.Events.CrudEven