How to insert line break <br /> in the XML text node  
Author Message
Granada





PostPosted: XML and the .NET Framework, How to insert line break <br /> in the XML text node Top

Hi,

I am writing a paragraph in the XML node.

e.g. <job Title = "Ex1", Desc = "Ex1" />

The Description node spans to multiple lines and I want to add line breaks at appropriate places.

How can I do that



.NET Development25  
 
 
Dimitre_Novatchev - MSFT





PostPosted: XML and the .NET Framework, How to insert line break <br /> in the XML text node Top

The following XSLT transformation:

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html>

Description: <br />

<xsl:call-template name="multiLineText">

<xsl:with-param name="pText" select=" "/>

</xsl:call-template>

</html>

</xsl:template>

<xsl:template name="multiLineText">

<xsl:param name="pText"/>

<xsl:choose>

<xsl:when test="contains($pText, '&#xA;')">

<xsl:value-of select="substring-before($pText,'&#xA;')"/>

<br />

<xsl:call-template name="multiLineText">

<xsl:with-param name="pText"

select="substring-after($pText,'&#xA;')"/>

</xsl:call-template>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="$pText"/>

</xsl:otherwise>

</xsl:choose>

</xsl:template>

</xsl:stylesheet>

when applied on this source xml documet:

<job Title = "Ex1"

Desc =

"Line 1 11111

Line 2 22222

Line 3 33333

"

/>

produces the wanted result:

<html>

Description: <br>Line 1 11111

<br> Line 2 22222

<br> Line 3 33333

<br> </html>

Cheers,
Dimitre Novatchev


 
 
Alexey Raga





PostPosted: XML and the .NET Framework, How to insert line break <br /> in the XML text node Top

Use &lt; and &gt; symbols instead of < and >.

So it should be possible to write:

<job Title = "Ex1", Desc = "Ex1&lt;br&gt;Ex2" />

And you will have Ex1<br>Ex2 in your code.