XML : XSL: Unable to replace a character by newline character

I have a requirement where I have to read some data and then reformat such that each part of the data is in new line. For instance, the data I have is:

dataLine1* dataLine2* dataLine3* dataLine4* dataLine5


and result I expect is:

dataLine1
* dataLine2
* dataLine3
* dataLine4
* dataLine5

So basically, it boils down to replacing * with 'newlinecharater*'. However, I am still at beginners level in XSL and not sure how to achieve this.

The code I have is:

  <!-- START: Code to replace the data within a string since I am working on XSLT 0.1 -->     <xsl:template name="string-replace-all">      <xsl:param name="text" />      <xsl:param name="replace" />      <xsl:param name="by" />      <xsl:choose>        <xsl:when test="contains($text, $replace)">          <xsl:value-of select="substring-before($text,$replace)" />          <xsl:value-of select="$by" />          <xsl:call-template name="string-replace-all">            <xsl:with-param name="text"            select="substring-after($text,$replace)" />            <xsl:with-param name="replace" select="$replace" />            <xsl:with-param name="by" select="$by" />          </xsl:call-template>        </xsl:when>        <xsl:otherwise>          <xsl:value-of select="$text" />        </xsl:otherwise>      </xsl:choose>    </xsl:template>  <!-- END: Code to replace the data within a string since I am working on XSLT 0.1 -->    <xsl:variable name="CPC" select="./_line_item_comment"/>  <xsl:variable name="newline"><xsl:text>&#10;</xsl:text></xsl:variable>    <xsl:variable name="myVar">      <xsl:call-template name="string-replace-all">        <xsl:with-param name="text" select="substring-after($CPC,'!$!')" />        <xsl:with-param name="replace" select="'*'" />        <xsl:with-param name="by" select="$newline" /> <!-- Here I have to give the newline character -->      </xsl:call-template>    </xsl:variable>    <xsl:value-of select="$myVar"/>    

Thanks in advance!

Best,
Shikhar

No comments:

Post a Comment