with only one node? Hi, I have a node which contains a message like string1 line 2 sting3 but when it disp...">

Xslt replace \ n <br/"> with only one node?

Hi, I have a node <msg> which contains a message like

string1
line 2
sting3

but when it displays, it displays the entire single line, how can I replace all \ n with <br /> s.

I tried

<xsl: value-select = 'replace (msg, "& #xA;", "<br />")' />

but i get this error

Error loading stylesheet: Invalid XSLT / XPath function.

how to do it?

+8
xslt
source share
3 answers

Call this template on the line you want to process:

<xsl:template name="break"> <xsl:param name="text" select="string(.)"/> <xsl:choose> <xsl:when test="contains($text, '&#xa;')"> <xsl:value-of select="substring-before($text, '&#xa;')"/> <br/> <xsl:call-template name="break"> <xsl:with-param name="text" select="substring-after($text, '&#xa;')" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose> </xsl:template> 

Like this (it will work with the current node):

 <xsl:template match="msg"> <xsl:call-template name="break" /> </xsl:template> 

or like this, explicitly passing the parameter:

 <xsl:template match="someElement"> <xsl:call-template name="break"> <xsl:with-param name="text" select="msg" /> </xsl:call-template> </xsl:template> 

I think you are working with an XSLT 1.0 processor, and replace () is the function that was introduced with XSLT / XPath 2.0.

+20
source share

 <pre> Jayakumar Kulkarni (Consultant) : Rematr 01 Jayakumar Kulkarni (Consultant) : 3rd comment </pre> 

Try this tag above.

0
source share

You can also achieve this with a simple HTML tag,
Try this <pre> before the message and close it after the message.

 <pre> Jayakumar Kulkarni (Consultant) : Remark Jayakumar Kulkarni : Rematr 01 Jayakumar Kulkarni : comment</pre> 
-2
source share

All Articles