You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Bennett <be...@glengroup.com> on 2003/10/07 21:32:14 UTC

text node to separate paragraphs

Hi,

	Does anyone know if there's a way to wrap individual paragraphs of a 
text node stored in an xml source document in an output element?
	I've seen all kinds of &#xA0; to-<br/> examples but no examples of 
detecting the &#xA0; in the source document and then using it somehow 
to wrap each paragraph individually like:

<p>paragraph1</p>
<p>paragraph2</p>
...


Does anyone have any ideas/ code samples?

Thank you,
Bennett


Re: text node to separate paragraphs

Posted by Johannes Lebek <jo...@gmx.de>.
Hi Bennett,

at first sight, I would say, this could be done by using function 
substring-before() in a recursive template:

<xsl:variable name="paragraph-delimiter">&#xA0;</xsl:variable>

<xsl:template name="print-paragraph">
   <xsl:param name="text"/>

   <xsl:choose>
     <xsl:when test="substring-before($text, $paragraph-delimiter) = ''>
       <xsl:choose>
         <xsl:when test="starts-with($text, $paragraph-delimiter)">
           <xsl:call-template name="print-paragraph">
             <xsl:with-param name="text" select="substring-after($text, 
$paragraph-delimiter)"/>
           </xsl:call-template>
         </xsl:when>
         <xsl:when test="not($text = '')">
           <p><xsl:value-of select="$text"/></p>
         </xsl:when>
       </xsl:choose>
     </xsl:when>
     <xsl:otherwise>
       <p><xsl:value-of select="substring-before($text, 
$paragraph-delimiter)"/></p>
       <xsl:call-template name="print-paragraph">
         <xsl:with-param name="text" select="substring-after($text, 
$paragraph-delimiter)"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

...

<!-- call to start printing of paragraphs -->
<xsl:call-template name="print-paragraph">
   <xsl:with-param name="text" select="'This is &#xA0; sample text.'"/>
</xsl:call-template>

I did not test it, but I suppose you got the idea of it. So if there is 
an error in my snippet you might be able to fix it. If not, tell me.
Hope this was helpful,

Johannes




Bennett wrote:
> Hi,
> 
>     Does anyone know if there's a way to wrap individual paragraphs of a 
> text node stored in an xml source document in an output element?
>     I've seen all kinds of &#xA0; to-<br/> examples but no examples of 
> detecting the &#xA0; in the source document and then using it somehow to 
> wrap each paragraph individually like:
> 
> <p>paragraph1</p>
> <p>paragraph2</p>
> ...
> 
> 
> Does anyone have any ideas/ code samples?
> 
> Thank you,
> Bennett
> 
>