I'd like to donate an open source JSP tag library I've been working on for
while to jakarta taglibs. I would need to get permission of the client I
developed it with first to change licence to ASF - I just wanted to check if
people would like it to be added to jakarta first to save me jumping
needlessly through some legal hoops.
"xtags" implements an XSLT-like language in JSP allowing XML to be styled
and processed from directly within a JSP page using XSLT and XPath
techniques.
Currently its all on SourceForge here:
http://xtags.org
There's the reference documentation there too such as the full tag
reference:
http://xtags.org/xtags.html
The easiest way to get a handle on what xtags is and how it works is to
download it, try out the example web apps and go through some example JSP
sources. A brief summary now follows.
xtags uses XPath expressions rather like XSLT does to allow you to process
XML in a powerful way, branching, iterating and formatting XML. xtags also
uses XSLT-like tags.
Loops are as follows (an optional variable name can be specified to define a
scriptlet expression inside the loop):-
<xtags:foreach select="expression">
...
</xtags:foreach>
Simple conditional branching is:-
<xtags:if test="booeanExpression">
...
</xtags:if>
More complex conditional branching is:-
<xtags:choose>
<xtags:when test="booeanExpression">
...
</xtags:when>
<xtags:when test="booeanExpression2">
...
</xtags:when>
<xtags:otherwise>
...
</xtags:otherwise>
</xtags:choose>
Expression evaluation
<xtags:valueof select="expression"/>
Defining scriptlet variables
<xtags:variable name="variableName" select="expression"/>
All these tags are very similar to their XSLT equivalents, so anyone who's
done XSLT before should find them familiar.
There's also an <xtags:style> tag which behaves quite like the existing XSL
taglib in Jakarta, performing a complete XSL transform in one tag.
XPath expressions can use variables with the syntax $foo.
xtags binds these variables to either page/request/session/application scope
attributes or request parameters which allows xtags to be used as a
conditional logic scripting language too - even without the existence of XML
documents.
For example, the following JSP would branch logically based on the value of
the (say) request parameter "option":-
<xtags:choose>
<xtags:when test="$option='a'">
current option is 'a'
</xtags:when>
<xtags:when test="$option='b'">
current option is 'b'
</xtags:when>
<xtags:otherwise>
no valid option selected
</xtags:otherwise>
</xtags:choose>
xtags even supports the <xtags:stylesheet> <xtags:template> and
<xtags:applytemplates> tags from XSLT too though the body of a template must
be an Action object or a seperate JSP file.
To close with here's a hello-world type bit of xtags JSP which styles any
RSS news feed and prints the headline stories with hypertext links into a
bullet list. (It actually prints the top Java news articles from
moreover.com). Though this may look similar to XSLT, remember that any JSP
tags or scriptlets can be used anywhere in this page:-
<html>
<body>
<h1>Hello RSS</h1>
<ul>
<xtags:document
uri="http://p.moreover.com/cgi-local/page?c=Java%20news&o=rss">
<xtags:foreach select="//item">
<xtags:variable name="url" type="string" select="link"/>
<li>
<a href="<%= url %>">
<xtags:valueof select="title"/>
</a>
-
<xtags:valueof select="description"/>
</li>
</xtags:foreach>
</xtags:document>
</ul>
</body>
</html>
Would people be happy to see this tag library donated to jakarta-taglibs?
James