cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Quinn <je...@media.demon.co.uk>
Subject a handy template for LogicSheet writers
Date Fri, 06 Oct 2000 16:24:21 GMT

Dear All,

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, '&#10;') or contains($content,
'&#13;')">
			<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,'&#13;','&#10;')"/>
	<xsl:variable name="first" select="substring-before($ncontent, '&#10;')"/>
	<xsl:variable name="rest" select="substring-after($ncontent, '&#10;')"/>
	<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>


Hope this helps

regards Jeremy
-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <mailto:sharkbait@mac.com>     		 <http://www.media.demon.co.uk>
    <phone:+44.[0].20.7737.6831>        <pager:jermq@sms.genie.co.uk>

Mime
View raw message