[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: insert tags out of context in XSL

Subject: Re: insert tags out of context in XSL
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Fri, 3 May 2002 11:58:47 -0400
insert linefeed into xml
[Peter Carlson]
>
> 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>.
>

Do not think like this.  XSLT is intended to produce trees, not text
fragments.  Try to think in terms of tree fragments, not string fragments.
>
> Since these tags are out of context in the xsl, it won't work since it's
not
> valid XML. I tried using the &lt;para&gt;, but they are considered tags in
> the next transform.
>

Thinking in tree - or well-formed element - terms, you really want to break
up the text into blocks, each of which is contained in its own "para"
element.  The break marker is a line feed, which will be a &#10; character.
You can break up the blocks using the substring-before and substring-after
functions.

You process all the blocks,  not by inserting a text fragment when you get
to a marker, but by sending each successive part of the text to the template
that knows how to do the job.  Substring-before lets you get the first
block, which you process, and substring-after gets you the rest of the text,
which you recursively send to the same template until there are no more
blocks to separate out.

No doubt Dimitre has an FXSL functional programming function that will do it
too.

Here's a stylesheet fragment that does the job:

<xsl:template match="/root">
<result>
 <xsl:call-template name='split-into-paras'>
  <xsl:with-param name='text' select='para'/>
 </xsl:call-template>
</result>
</xsl:template>

<xsl:template name='split-into-paras'>
 <xsl:param name='text'/>
 <xsl:variable name='first' select='substring-before($text,"&#10;")'/>
 <xsl:variable name='rest' select='substring-after($text,"&#10;")'/>
 <xsl:if test='$first!=""'>
    <para><xsl:value-of select='$first'/></para>
 </xsl:if>

 <xsl:if test='$rest!=""'>
  <xsl:call-template name='split-into-paras'>
   <xsl:with-param name='text' select='$rest'/>
  </xsl:call-template>
 </xsl:if>
</xsl:template>

Cheers,

Tom P




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.