Replace string with elements recursively

I am trying to modify strings like: Some {words} should be {bold} ... to something like Some <b>words</b> should be <b>bold</b> ...

However, my implementation forgets all <b> elements but the last one: Some words should be <b>bold</b> ...

I think, that the substring-before() removes the already inserted <b> elements. Here is my code:

<xsl:template name="replace">
  <xsl:param name="input"/>

  <xsl:variable name="before" select="substring-before( $input, '{' )" />
  <xsl:variable name="after" select="substring-after( $input, '}' )" />
  <xsl:variable name="replace" select="substring-after( substring-before( $input, '}' ), '${' )" />

    <xsl:when test="$replace">
      <xsl:call-template name="replace">
        <xsl:with-param name="input">
          <xsl:value-of select="$before" />
          <xsl:element name="b">
            <xsl:value-of select="$replace" />
          <xsl:value-of select="$after" />
      <xsl:copy-of select="$input" />

Any ideas? Thanks for your help.


As you have tagged the question as XSLT 2.0 I strongly suggest to use analyze-string i.e. with

<text>Some {words} should be {bold} ...</text>

and the stylesheet


  <xsl:template match="text">
    <xsl:analyze-string select="." regex="\{{(.*?)\}}">
          <xsl:value-of select="regex-group(1)"/>
        <xsl:value-of select="."/>



Some <b>words</b> should be <b>bold</b> ...

Need Your Help

Back key navigation doesn't work even though focus is set to true

android qt focus

In my Qt Android app I push an Item from the menu to the StackView:

How to set Pie chart values in %

java jfreechart

I am using JFreechart for creating chart. When i am creating pie chart the values for the pie chart are displaying with integer format.But i need those values in Percentage.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.