You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Richard Lewis <ri...@fastmail.co.uk> on 2007/03/19 18:04:20 UTC

Tuning XSP output

Hello Cocoon users,

Using Cocoon 2.1.10.

I'm just working on some XSP logic sheets using ESQL to create XML views of my 
MySQL database.

There are two things I'd like to be able to do:

1) Stop it from producing empty elements.

e.g. I have: <duration><esql:get-string column="duration" /></duration> which, 
if the duration field is empty, will create an empty <duration /> element. Is 
there an automatic way to stop these from happening? (I understand I could 
just use an XSLT transformation to get rid of them but its seems a bit of 
hack.)

2) Some of my fields (e.g. biography) are long textual fields which include 
line spaces. Is there a way to capture those lines and wrap them up in 
elements? At the moment, the XML document includes the line spaces, but it 
would be much easier to work with semantically encoded line spaces.

e.g. the biography field contains the text:
"John Bloggs (b. 1979, Ireland).

Bloggs began his..."

would come out as:
<biography>
  <l>John Bloggs (b. 1979, Ireland).</l>
  <l>Bloggs began his...</l>
</biography>

Again, I guess there could be a way of writing some <xsp:logic> to handle 
this, though it would be cool if there was something less hackish. (Also, 
I've no idea how I would go about writing that particular hack anyway!)

Cheers,
Richard
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
http://www.richard-lewis.me.uk/
JID: ironchicken@jabber.earth.li
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

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


Re: Tuning XSP output

Posted by Armin Ehrenfels <Ar...@t-online.de>.
Hi Richard,

a few years ago, I developed an application using Cocoon-2.0.4 and XSP 
stylesheets. One good way to find out what went wrong was looking at the 
Java source file which is generated from an XSP stylesheet. There, you 
will certainly be able to see why "p cannot be resolved".

HTH

Armin

Richard Lewis wrote:

>On Thursday 22 March 2007 15:52, Richard Lewis wrote:
>  
>
>>On Tuesday 20 March 2007 10:20, Tobia wrote:
>>    
>>
>>>Richard Lewis wrote:
>>>      
>>>
>>>>1) Stop it from producing empty elements.
>>>><duration><esql:get-string column="duration" /></duration>
>>>>        
>>>>
>>>      
>>>
>>>>2) Some of my fields (e.g. biography) are long textual fields which
>>>>include line spaces. Is there a way to capture those lines and wrap
>>>>them up in elements?
>>>>        
>>>>
>>>Again untested:
>>>
>>>	String biography = <esql:get-string column="biography"/>;
>>>	for (String para : biography.split("\\n\\s*\\n")) {
>>>	  <l><xsp:expr>para</xsp:expr></l>
>>>	}
>>>      
>>>
>>Thanks for these pointers. I'm quite new to XSP and logicsheets and I'm now
>>having trouble getting them to work.
>>
>>Does anyone have any ideas why my logicsheet won't work?
>>
>>    
>>
>OK, I'm still not having any success with this logicsheet. At the moment I'm 
>just transforming my XSP with my logicsheet XSLT, storing the result and 
>using that in my sitemap rather than the original XSP.
>
>This lead me to discover that I get file not found exceptions when the 
>xmlns:sara namespace is in the generated XSP. Might this be a problem?
>
>I've also found another problem with my XSP that I can't seem to fix. My 
>logicshhet contains the following (slightly altered from previous post):
>
><xsl:template match="sara:get-string">
>  <xsl:if test="@exclude-values">
>    <xsp:logic>
>      String <xsl:value-of select="@column" />_exclude[] = "<xsl:value-of 
>select="@exclude-values" />".split("\\s+");
>    </xsp:logic>
>  </xsl:if>
>  <xsp:logic>
>    String _<xsl:value-of select="@column" /> = <esql:get-string 
>column="{@column}" />;
>    if (_<xsl:value-of select="@column" />.length() > 0) {
>    <xsl:element name="{@tag-name}">
>      for (String p : _<xsl:value-of select="@column" />.split("\\n")) {
>      <l><xsp:expr>p</xsp:expr></l>
>      }
>    </xsl:element>
>    }
>  </xsp:logic>
></xsl:template>
>
>I get error messages in the for loop saying that "p cannot be resolved":
>
>org.apache.cocoon.components.language.LanguageException: Error compiling 
>expand_artist2xml_xsp:
>ERROR 1 (org/apache/cocoon/www/sara/maps/expand_artist2xml_xsp.java):
>...
> );
> 
>// start error (lines 438-438) "p cannot be resolved"
> XSPObjectHelper.xspExpr(contentHandler, p);
> 
>// end error
>  
> _endElem(
> "",
>
>I tried altering the logicsheet so that all the "p"s had unique names but it 
>gave the same error.
>
>Any ideas how I fix this?
>
>Cheers,
>Richard
>  
>


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


Re: Tuning XSP output

Posted by Richard Lewis <ri...@fastmail.co.uk>.
On Thursday 22 March 2007 15:52, Richard Lewis wrote:
> On Tuesday 20 March 2007 10:20, Tobia wrote:
> > Richard Lewis wrote:
> > > 1) Stop it from producing empty elements.
> > > <duration><esql:get-string column="duration" /></duration>
> >
> >
> > > 2) Some of my fields (e.g. biography) are long textual fields which
> > > include line spaces. Is there a way to capture those lines and wrap
> > > them up in elements?
> >
> > Again untested:
> >
> > 	String biography = <esql:get-string column="biography"/>;
> > 	for (String para : biography.split("\\n\\s*\\n")) {
> > 	  <l><xsp:expr>para</xsp:expr></l>
> > 	}
>
> Thanks for these pointers. I'm quite new to XSP and logicsheets and I'm now
> having trouble getting them to work.
>
> Does anyone have any ideas why my logicsheet won't work?
>
OK, I'm still not having any success with this logicsheet. At the moment I'm 
just transforming my XSP with my logicsheet XSLT, storing the result and 
using that in my sitemap rather than the original XSP.

This lead me to discover that I get file not found exceptions when the 
xmlns:sara namespace is in the generated XSP. Might this be a problem?

I've also found another problem with my XSP that I can't seem to fix. My 
logicshhet contains the following (slightly altered from previous post):

<xsl:template match="sara:get-string">
  <xsl:if test="@exclude-values">
    <xsp:logic>
      String <xsl:value-of select="@column" />_exclude[] = "<xsl:value-of 
select="@exclude-values" />".split("\\s+");
    </xsp:logic>
  </xsl:if>
  <xsp:logic>
    String _<xsl:value-of select="@column" /> = <esql:get-string 
column="{@column}" />;
    if (_<xsl:value-of select="@column" />.length() > 0) {
    <xsl:element name="{@tag-name}">
      for (String p : _<xsl:value-of select="@column" />.split("\\n")) {
      <l><xsp:expr>p</xsp:expr></l>
      }
    </xsl:element>
    }
  </xsp:logic>
</xsl:template>

I get error messages in the for loop saying that "p cannot be resolved":

org.apache.cocoon.components.language.LanguageException: Error compiling 
expand_artist2xml_xsp:
ERROR 1 (org/apache/cocoon/www/sara/maps/expand_artist2xml_xsp.java):
...
 );
 
// start error (lines 438-438) "p cannot be resolved"
 XSPObjectHelper.xspExpr(contentHandler, p);
 
// end error
  
 _endElem(
 "",

I tried altering the logicsheet so that all the "p"s had unique names but it 
gave the same error.

Any ideas how I fix this?

Cheers,
Richard
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
http://www.richard-lewis.me.uk/
JID: ironchicken@jabber.earth.li
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

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


Re: Tuning XSP output

Posted by Richard Lewis <ri...@fastmail.co.uk>.
On Tuesday 20 March 2007 10:20, Tobia wrote:
> Richard Lewis wrote:
> > 1) Stop it from producing empty elements.
> > <duration><esql:get-string column="duration" /></duration>
>
> I guess you need to put it inside a Java if statement.
> You can wrap it all in a logicsheet, for convenience:
>
> 	<my:get-element column="duration"/>
>
> Something like this (untested):
>
> 	<xsl:template match="my:get-element">
> 	  <xsp:logic>
> 	    if (<esql:get-string column="{@column}"/>.length() > 0) {
> 	      <xsl:element name="{@column}">
> 	        <esql:get-string column="{@column}"/>
> 	      </xsl:element>
> 	    }
> 	  </xsp:logic>
> 	</xsl:template>
>
> > 2) Some of my fields (e.g. biography) are long textual fields which
> > include line spaces. Is there a way to capture those lines and wrap
> > them up in elements?
>
> Again untested:
>
> 	String biography = <esql:get-string column="biography"/>;
> 	for (String para : biography.split("\\n\\s*\\n")) {
> 	  <l><xsp:expr>para</xsp:expr></l>
> 	}
>
Thanks for these pointers. I'm quite new to XSP and logicsheets and I'm now 
having trouble getting them to work. I've used your code to create the 
following logicsheet (apologies for the verboseness, its just in case the 
problem is here):

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:sara="http://www.sara.uea.ac.uk/xsp"
    xmlns:xsp="http://apache.org/xsp"
    xmlns:esql="http://apache.org/cocoon/SQL/v2"
    version="1.0">

<xsl:template match="xsp:page">
  <xsl:copy>
    <xsl:apply-templates select="@*" />
    <xsl:apply-templates />
  </xsl:copy>
</xsl:template>

<xsl:template match="sara:get-string">
  <xsl:if test="@exclude-values">
    <xsp:logic>
      String exclude[] = <xsl:value-of 
select="@exclude-values" />.split("\\s+");
    </xsp:logic>
  </xsl:if>
  <xsp:logic>
    String lines[] = <esql:get-string column="{@column}" />.split("\\n");
    if (lines.length > 0) {
    <xsl:element name="{@column}">
      for (int i = 0; i &lt; lines.length; i++) {
      <l><xsp:expr>lines[i]</xsp:expr></l>
      }
    </xsl:element>
    }
  </xsp:logic>
</xsl:template>

<xsl:template match="@*|node()" priority="-1">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

And in my XSP I have, for example:

<name>
  <sara:get-string column="first_name" tag-name="first" />
  <sara:get-string column="last_name" tag-name="last" />
</name>

Both of these files are stored in:
/home/richard/Documents/sara/cocoon/maps

and my Cocoon installation directory is:
/usr/share/cocoon

and it contains a symlink called 'sara' which points to:
/home/richard/Documents/sara/cocoon
(this directory contains my sitemap.xmap file)

At first I tried to add my logicsheet to the cocoon.xconf file like this:

<target-language name="java">
...
<builtin-logicsheet>
  <parameter name="prefix" value="sara" />
  <parameter name="uri" value="http://www.sara.uea.ac.uk/xsp" />
  <parameter name="href" 
value="file:///home/richard/Documents/sara/maps/sara-logicsheet.xsl" />
</builtin-logicsheet>

But when I made the relevant request, the resultant XML document just 
contained my <sara:get-string> elements verbitum (rather than interpretting 
them). I tried altering the the file: protocol to resource: but it didn't 
make any difference.

So I then tried using the logicsheet processing instruction in my XSP instead:
<?xml-logicsheet href="maps/sara-logicsheet.xsl" ?>

But now it keeps saying that it can't find the sara-logicsheet.xsl file. I've 
tried several different paths. I get:

java.io.FileNotFoundException: /home/richard/Documents/sara/maps/sara-logicsheet.xsl 
(No such file or directory)

I've even tried:
<?xml-logicsheet 
href="file:///home/richard/Documents/sara/cocoon/maps/sara-logicsheet.xsl" ?>

Does anyone have any ideas why my logicsheet won't work?

Cheers,
Richard
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
http://www.richard-lewis.me.uk/
JID: ironchicken@jabber.earth.li
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

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


Re: Tuning XSP output

Posted by Tobia <to...@linux.it>.
Richard Lewis wrote:
> 1) Stop it from producing empty elements.
> <duration><esql:get-string column="duration" /></duration>

I guess you need to put it inside a Java if statement.
You can wrap it all in a logicsheet, for convenience:

	<my:get-element column="duration"/>

Something like this (untested):

	<xsl:template match="my:get-element">
	  <xsp:logic>
	    if (<esql:get-string column="{@column}"/>.length() > 0) {
	      <xsl:element name="{@column}">
	        <esql:get-string column="{@column}"/>
	      </xsl:element>
	    }
	  </xsp:logic>
	</xsl:template>


> 2) Some of my fields (e.g. biography) are long textual fields which
> include line spaces. Is there a way to capture those lines and wrap
> them up in elements?

Again untested:

	String biography = <esql:get-string column="biography"/>;
	for (String para : biography.split("\\n\\s*\\n")) {
	  <l><xsp:expr>para</xsp:expr></l>
	}

All the other methods I can think of are less reliable, less performant
and much more lenghty.


Tobia

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