cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Lewis <richardle...@fastmail.co.uk>
Subject Re: Tuning XSP output
Date Thu, 22 Mar 2007 15:52:31 GMT
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


Mime
View raw message