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

Re: Angle brackets and string manipulation

Subject: Re: Angle brackets and string manipulation
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Mon, 10 Mar 2003 06:45:08 +0100
angle bracket xsl
>
> Basic problem is that I had to resort to the always infamous
> disable-output-escaping to substitute a <br /> for a marker character(s)
> in a text() node string.  Did I happen upon an actual valid use of
> d-o-e, or am I missing better way to do this?

There is a better way.


> <xsl:template match="text()">
>
>   <!-- use a variable to allow additional substring substitions
>        not shown to simplify -->
>   <xsl:variable name="t1">
>     <xsl:call-template name="insert_breaks">
>       <xsl:with-param name="source_string" select="."/>
>       <xsl:with-param name="marker" select="'!br;'"/>
>     </xsl:call-template>
>   </xsl:variable>

The "insert_breaks" template could create <br /> ***nodes*** -- not simply
insert text.


>   <xsl:value-of disable-output-escaping="yes" select="$t1"/>

Because the result is immediately copied, the above instruction is not
necessary at all -- simply remove it. Also do not define the xsl:variable
"t1", but simply call the template to produce its result.

     <xsl:call-template name="insert_breaks">
       <xsl:with-param name="source_string" select="."/>
       <xsl:with-param name="marker" select="'!br;'"/>
     </xsl:call-template>


> <xsl:template name="insert_breaks">
>
>   <xsl:param name="source_string" select="."/>
>   <xsl:param name="marker"/>
>
>   <!-- If $marker is in the $source_string -->
>   <xsl:if test="contains($source_string,$marker)">
>     <!-- then replace it with "&lt;br /&gt;" and look for another -->
>     <xsl:call-template name="insert_breaks">
>       <xsl:with-param name="source_string">
>         <!-- make the substitution by taking everything before the
>              marker, insert the br element, and finish with everything
>              after the break marker -->
>         <xsl:value-of select="substring-before( $source_string,
>                                                 $marker )"/>
>         <xsl:text>&lt;br /&gt;</xsl:text>
>         <xsl:value-of select="substring-after( $source_string,
>                                                $marker )"/>
>       </xsl:with-param>
>       <xsl:with-param name="marker" select="$marker"/>
>     </xsl:call-template>
>   </xsl:if>

This is creating just text -- should create a sequence of text nodes and
"br" elements:

   <xsl:if test="contains($source_string,$marker)">
    <xsl:value-of select="substring-before( $source_string, $marker )"/>
    <br />
     <xsl:call-template name="insert_breaks">
       <xsl:with-param name="source_string" select="substring-after(
$source_string, $marker )"/">
       <xsl:with-param name="marker" select="$marker"/>
     </xsl:call-template>

>
>   <!-- terminating case where the $marker is not found in the
>        source string -->
>   <xsl:if test="not(contains($source_string,$marker))">
>     <xsl:value-of select="$source_string"/>
>   </xsl:if>
>
> </xsl:template>


Hope this helped.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL





 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.