Subject: Re: [xsl] insert tags out of context in XSL From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 3 May 2002 16:46:00 +0100 |
Hi Peter, > I am trying to break up a single block of text into multiple blocks > at the linefeed marker. > > I found the l2br solution in the FAQ, but I don't want to put a <br > />, I want to use </para><para>. XSLT builds up result trees, containing elements, not strings containing tags. You can achieve what you want to achieve, but you have to think of it in terms of creating para elements rather than inserting tags. So to rephrase: you want to create para elements around each substring within the text, where substrings are delimited by newlines. You need a recursive template that takes a string: <xsl:template name="paragraphise"> <xsl:param name="string" /> ... </xsl:template> If the string doesn't contain a newline, then you just want to create a para element around the string: <xsl:template name="paragraphise"> <xsl:param name="string" /> <xsl:choose> <xsl:when test="contains($string, '
')"> <para><xsl:value-of select="$string" /></para> </xsl:when> <xsl:otherwise> ... </xsl:otherwise> </xsl:choose> </xsl:template> Otherwise you want to create a para element around the first part of the string, before the newline character, and then call the template again, on the string after the newline character, to paragraphise that: <xsl:template name="paragraphise"> <xsl:param name="string" /> <xsl:choose> <xsl:when test="contains($string, '
')"> <para><xsl:value-of select="$string" /></para> </xsl:when> <xsl:otherwise> <para> <xsl:value-of select="substring-before($string, '
')" /> </para> <xsl:call-template name="paragraphise"> <xsl:with-param name="string" select="substring-after($string, '
')" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> Another option would be to use the standard tokenize templates and extension functions to tokenize your string on the newline delimiter, and turn each token into a paragraph. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] insert tags out of contex, David Carlisle | Thread | Re: [xsl] insert tags out of contex, Thomas B. Passin |
Re: [xsl] insert tags out of contex, David Carlisle | Date | Re: [xsl] insert tags out of contex, Thomas B. Passin |
Month |