[opencms] [opencms-dev] cmstag:contentloop scriptlet equivalent
Jorge González
informatico at hotelparadisepark.com
Thu Nov 17 18:32:17 CET 2005
Let's rock.
XML comes to help you from hell:
Autoresponse: You can use the worder <x> tags from jstl, this way:
------------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@page pageEncoding="UTF-8"%>
<%@page import="org.opencms.jsp.*, org.opencms.file.*" %>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
<%@ taglib prefix="x" uri="/WEB-INF/x.tld" %>
<%@ page import="org.opencms.jsp.*" %>
<%@ taglib prefix="cmstag" uri="http://www.opencms.org/taglib/cms" %>
<%
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
response);
String uri = request.getParameter("resource");
String lang = "en";
CmsFile file = cms.getCmsObject().readFile(uri);
// note that this doesn't handle charsets
byte[] content = file.getContents();
String result = new String(content);
pageContext.setAttribute("xml", result);
%>
<c:set var="xsl">
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:for-each select="//node()[@language='<%=lang%>']//yyy">
name=<xsl:value-of select="name"/>
description=<xsl:value-of select="description/content"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</c:set>
<x:transform xml="${xml}" xslt="${xsl}" />
PD: One question: is this more or less efficient than cmstag:contentshow ???
More information about the opencms-dev
mailing list