[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: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 3 May 2002 16:46:00 +0100
xsl string insert
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, '&#xA;')">
      <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, '&#xA;')">
      <para><xsl:value-of select="$string" /></para>
    </xsl:when>
    <xsl:otherwise>
      <para>
        <xsl:value-of select="substring-before($string, '&#xA;')" />
      </para>
      <xsl:call-template name="paragraphise">
        <xsl:with-param name="string"
                        select="substring-after($string, '&#xA;')" />
      </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

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.