阅读少于一分钟
Recently a coleague asked if it was possible to call java from XSL.
It is possible, and here is the example I provided.
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:getterUtil="xalan://com.liferay.portal.kernel.util.GetterUtil" xmlns:java="http://xml.apache.org/xalan/java" xmlns:userLocalServiceUtil="xalan://com.liferay.portal.service.UserLocalServiceUtil" exclude-result-prefixes="java" extension-element-prefixes="getterUtil userLocalServiceUtil"> <xsl:output method="html" omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:variable name="remote-user" select="/root/request/remote-user" /> <xsl:text>Remote User: </xsl:text> <xsl:value-of select="$remote-user" /> <div class="separator"><!--//--></div> <xsl:choose> <xsl:when test="$remote-user != ''"> <xsl:variable name="user" select="userLocalServiceUtil:getUserById(getterUtil:getLong($remote-user))" /> <xsl:text>Hello </xsl:text> <xsl:value-of select="java:getFullName($user)" /> <xsl:text>!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>Hello! Please log in.</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>VM (VTL) is great and all, but when it comes to dealing with XML data, you simply can't beat the power of XSL. Add to that the power of inline java and you can do some nifty stuff.
Related Assets...
未找到结果
More Blog Entries...
Daniel Carrillo Broeder
十月 21, 2026
Community
Company
Feedback


