Re: [xsl] Re: Angle brackets and string manipulation

Subject: Re: [xsl] Re: Angle brackets and string manipulation
From: Steve Rosenberry <Steve.Rosenberry@xxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 10 Mar 2003 14:41:02 -0500

Dimitre Novatchev wrote:
> 
> The "insert_breaks" template could create <br /> ***nodes*** -- not simply
> insert text.
>
> ...
> 
> Also do not define the xsl:variable "t1", but simply call the template 
> to produce its result.
> 
> ...
> 
> This [the above snipped version] 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>
> 

Thanks, Dimitre.  I got the insert_breaks template to work with your
suggested snippet shown above to create nodes instead of just a text
string.  Indeed this was one of my early attempts.  The problem remains
that there is more than one substitution required, thus the reason for
variable, "t1".  I pass "t1" to the next substitution -- a simple string
substitution, no node creation -- and subsequently lose the <br />
element. 

After bustin' my head against the wall for another few hours with
various combinations of node-set() calls here and there, I decided to
take a look at EXSLT to see what the string library had implemented, and
Jeni did not let me down -- a full-blown replace any darn thing(s) with
any darn thing(s) 'til your heart's content.  Final version and an
example of using str:replace for multiple substitutions with both string
and element replacements:

<xsl:template match="text()">

  <xsl:call-template name="str:replace">
    <xsl:with-param name="string" select="." />
    <xsl:with-param name="search">
      <t>!br;</t>       <!-- node names are unimportant -->
      <t>!emdash;</t>
    </xsl:with-param>
    <xsl:with-param name="replace">
      <br />		<!-- replacements by position for above -->
      <t>&#151;</t>
    </xsl:with-param>
  </xsl:call-template>

</xsl:template>

Thanks again, Dimitri and Jeni.

-- 
Steve Rosenberry
Sr. Partner

Electronic Solutions Company -- For the Home of Integration
http://ElectronicSolutionsCo.com

(610) 670-1710

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


Current Thread