cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simone cecchini <sim...@kiosco.org>
Subject separation of content *from* (logic *and* presentation) (should have been: Re: Moving XSP from XML to a stylesheet, request now gives error)
Date Fri, 23 Mar 2001 18:46:21 GMT
dear all,
a few days ago i discovered that the method i had chosen to implement the most important slice
of my project is rather frowned upon (btw, thanks, anthony, for your comments and explanation):
i was trying to turn an xml (content) document in an xsp page (by means of a stylesheet) that
should have been fed to an xsl stylesheet (much the same way jason did). being a novice, i
thought i was doing a cool thing because...
1 - the initial xml document contained the plain content: some <article> inside a <journal>
root document (this is generated by some users by way of forms, so i do not want anything
else to be put there inside).
2 - the xsp page it was xslt-transformed into contained just the logic (that's filtering some
contents on the basis of user authorization infos got from a database table)
3 - the last stylesheet formatted the result for presentation to the user
voilĂ ! a fine, neat, natural, sprectrumlike splitting of tasks: xml->xsp->xslt. it
sounded good to me.
the way i did it: the xml document contains the following pis:
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="journal.xsl" type="text/xsl"?>
[journal.xsl is the stylesheet used to fulfill the first transformation xml->xsp]

the stylesheet generates an xsp:page and has a
<xsl:processing-instruction name="cocoon-process">type="xsp"</xsl:processing-instruction>
somewhere, to get the xsp processor to run through the page, which also contained the xslt
tags due for presentation (actually, i haven't done the effort to separate logic from presentation
in this case).
there have been criticism to this solution, soundly backed up by the observation that it doesn't
fit well in with the original design of the xsp processor and that it will not be portable
to c2.
nonetheless, i haven't been able to conceive a better way of doing it or a better way of separating
the different frameworks.
while thinking about this, i recalled the trail started some weeks ago by uli mayring (subj:
app design philosophy rant), in which uli summed up two main principles of application design:
1) [Like above,] put everything in the XML file and use XSLT just for
straightforward and unintelligent rewriting of XML into HTML.
2) Write clean esql queries, then parse the generated XML intelligently in
an XSLT stylesheet and transform (not merely rewrite) to HTML.

in both of them, "esql query" - that's xsp - are kept with the original xml file (all xsp
processing must start from a chain which has an xsp page as first link!). as a consequence,
xsp gets more involved in content generation than in content manipulation, because having
an xsp page as the first link of the chain, i can not process plain documents other than by
xslt processor. [??]
logic is related as much to content generation (eg displaying data retrieved from a database)
as to content manipulation (eg filtering/transforming data output to the user), but how can
i get to manipulate plain content from an xml file?
i have tried and use logicsheets, instead of stylsheets, but even this way, i haven't found
a way to avoid the problem (suggestions are welcome).
i feel like there were a 'missing link', some kind of trick that would let me write down the
manipulating logic, without having to start it all from an xsp page. i think of this as "keeping
xsp [or something else...] with stylesheet", meaning that i can generate [on the fly, by means
of xsl] an xsp page for running (taglibs work almost this way: they transform an xsp page,
that's an xml page, into another). then i make the xsp processor working on the stylesheet
alone, instead of the xml file. the result gets combined with the original xml doc. in this
way i could separate content from the couple logic + presentation, treated by xsp.

will c1 deal with this issue? is it possible to apply the mentioned strategy without committing
some fault? does c2 deals with this issue? is this issue going to be treated somehow?

any comments, suggestions or scoldings (if needed) are very much welcome, just helping to
get out of the mist.
simone



At 23:00 3/22/01 -0600, you wrote:
>
>Cocoon 1.8.2 on Tomcat 2.2 on Linux (latest production releases).
>
>This fragment of code is part of a larger code that worked under .xml, but
>when I put it into a style sheet, I get this error:
>
>java.lang.Exception: XSP Java Compiler: Compilation failed for _sample.java
>28: Undefined variable or class name: request
>    static String filename = normalize(request.getRequestURI());
>
>
>
>Here's a code fragment of what I'm trying to do.
>
>
>
><?xml version="1.0"?>
>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>xmlns:xsp="http://www.apache.org/1999/XSP/Core">
>
>  <xsl:template match="/">
>   <xsl:processing-instruction
>name="cocoon-process">type="xsp"</xsl:processing-instruction>
>   <xsl:processing-instruction
>name="cocoon-process">type="xslt"</xsl:processing-instruction>
>   <xsl:processing-instruction name="xml-stylesheet">href="news-html.xsl"
>type="text/xsl"</xsl:processing-instruction>
>
>
>   <xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core"
>
>xmlns:request="http://www.apache.org/1999/XSP/Request">
>
>   <xsp:structure>
>    <xsp:include>java.net.*</xsp:include>
>   </xsp:structure>
>
>   <xsp:logic><![CDATA[
>    private String normalize(String string) { if (string == null) return "";
>else return string; }
>    static String filename = normalize(request.getRequestURI());
>    /*String pathname = normalize(XSPUtil.pathComponent(
>                           XSPUtil.relativeFilename(
>                            XSPUtil.fileComponent(filename), request,
>(ServletContext) context)
>                             ));*/
>    String pathname = "/var/tomcat/webapps/cocoon/courier/";
>    final File path = new File(pathname);
>    final String[] theList = path.list( new FilenameFilter() {
>        public boolean accept (File dir, String n) {
>         if (n.endsWith(".xml")) return true;
>         else return false; }});
>    static String metaContent = "news";
>
>(chop)
>
>-Jason Potkanski
>^
>
>
>---------------------------------------------------------------------
>Please check that your question has not already been answered in the
>FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
>To unsubscribe, e-mail: <cocoon-users-unsubscribe@xml.apache.org>
>For additional commands, e-mail: <cocoon-users-help@xml.apache.org>
>
>

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail: <cocoon-users-help@xml.apache.org>


Mime
View raw message