cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Green" <gree...@hotmail.com>
Subject Re: a handy template for LogicSheet writers
Date Tue, 07 Nov 2000 19:47:59 GMT
Hmmm... should I keep this on cocoon-dev or move it to xsp-dev? I couldn't 
get this to work, see below.

Jeremy Quinn <jermq@media.demon.co.uk> wrote:
>I needed an XSL Template to pass multiline strings to Java Methods.
>
>ie.
>
>	<mailer:signature>
>			--------------------------------------------------
>				Brought to you by Apache Cocoon XSP Mailer 1.0
>			--------------------------------------------------
>	</mailer:signature>
>
>becomes:
>
>	_mailer_N55be68.setSignature("" + "\n"
>	+ "			--------------------------------------------------" + "\n"
>	+ "				Brought to you by Apache Cocoon XSP Mailer 1.0" + "\n"
>	+ "			--------------------------------------------------" + "\n" + "");
>
>
>This is something that I believe other TagLibs want to be able to do, eg
>ESQL etc. so I thought I'd pass it on straight away.
>
>You use it by calling "get-nested-content" as usual ....
>
>If there are fixes or optimisations, please feed them back.
>
>And yes, I'll soon donate a mail sending TagLib for C1.
>
>
><xsl:template name="get-nested-content">
>	<xsl:param name="content"/>
>	<xsl:choose>
>		<xsl:when test="$content/*"><xsl:apply-templates
>select="$content/*"/></xsl:when>
>		<xsl:when test="contains($content, '
') or contains($content,
>'
')">
>			<xsl:call-template name="get-nested-strings">
>				<xsl:with-param name="content" select="$content"/>
>			</xsl:call-template>
>		</xsl:when>
>		<xsl:otherwise>"<xsl:value-of select="$content"/>"</xsl:otherwise>
>	</xsl:choose>
></xsl:template>
>
><xsl:template name="get-nested-strings">
>	<xsl:param name="content"/>
>	<xsl:variable name="ncontent" select="translate($content,'
','
')"/>
>	<xsl:variable name="first" select="substring-before($ncontent, '
')"/>
>	<xsl:variable name="rest" select="substring-after($ncontent, '
')"/>
>	<xsl:text>"</xsl:text><xsl:value-of 
>select="$first"/><xsl:text>"</xsl:text>
>	<xsl:if test="$rest">
>		<xsl:text> + "\n" +
></xsl:text>
>		<xsl:call-template name="get-nested-strings">
>			<xsl:with-param name="content" select="$rest"/>
>		</xsl:call-template>
>	</xsl:if>
></xsl:template>
>
>


I rewrote this to put it in util.xsl, like so:

  <!-- Multiline string (based on code by JQ) -->
  <xsl:template match="util:string">
    <xsl:choose>
      <xsl:when test="contains(., '
') or contains(.,
'
')">
        <xsl:call-template name="get-nested-strings">
          <xsl:with-param name="content" select="."/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>"<xsl:value-of select="."/>"</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="get-nested-strings">
    <xsl:param name="content"/>
      <xsl:variable name="first" select="substring-before($content, '
')"/>
      <xsl:variable name="rest" select="substring-after($content, '
')"/>
      <xsl:text>"</xsl:text><xsl:value-of 
select="$first"/><xsl:text>"</xsl:text>
      <xsl:if test="$rest">
        <xsl:text> + "\n" +
</xsl:text>
        <xsl:call-template name="get-nested-strings">
          <xsl:with-param name="content" select="$rest"/>
        </xsl:call-template>
      </xsl:if>
  </xsl:template>


However it generates invalid source code (cocoon 1.8.1-dev). Source code 
below. What am I doing wrong?

Test fragment:

  <xsp:logic>
   String para = <util:string>The content you are seeing in this page is 
provided to you
  by an XML content producer that was compiled into Java bytecode
  and executed at request time. This allows greater flexibility and
  ease of use for page programmers without any performance degradation
  since all XML parsing and such is precompiled and it's avoided at
  request time.</util:string>;
  </xsp:logic>

  <p><xsp:expr>para</xsp:expr></p>

Generated source code: First error is after "you".


   String para = "The" + "\n" +
"content" + "\n" +
"you" + "\n" +
"are" + "\n" +
"seeing" + "\n" +
"in" + "\n" +
"this" + "\n" +
"page" + "\n" +
"is" + "\n" +
"provided" + "\n" +
"to" + "\n" +
"you
" + "\n" +
"" + "\n" +
"by" + "\n" +
"an" + "\n" +
"XML" + "\n" +
"content" + "\n" +
"producer" + "\n" +
"that" + "\n" +
"was" + "\n" +
"compiled" + "\n" +
"into" + "\n" +
"Java" + "\n" +
"bytecode
" + "\n" +
"" + "\n" +
"and" + "\n" +
"executed" + "\n" +
"at" + "\n" +
"request" + "\n" +
"time." + "\n" +
"This" + "\n" +
"allows" + "\n" +
"greater" + "\n" +
"flexibility" + "\n" +
"and
" + "\n" +
"" + "\n" +
"ease" + "\n" +
"of" + "\n" +
"use" + "\n" +
"for" + "\n" +
"page" + "\n" +
"programmers" + "\n" +
"without" + "\n" +
"any" + "\n" +
"performance" + "\n" +
...



_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.


Mime
View raw message