0

How can I put double <br/> tags in an XSLT file for a double line break?

For example, I want to display something like below:

Hi Jessica,

Your account is activated!

so between the comma and "Your" I will put two <br/> tags.

My code currently is:

<xsl:value-of select="concat(demessage/TEXT.1, demessage/TEXT.SPACE, demessage/TEXT.2, '&lt;br/&gt;', '&lt;br/&gt;', demessage/TEXT.3)"/>

Respectively, TEXT.1 = Hi, TEXT.2 = Jessica, TEXT.3 = Your account is activated!

In this case, I think the double line break should work however, it is still giving me one new line.

Does anyone have any ideas why the transform is behaving like this?

4
  • "it is still giving me one new line." How are you testing this? Commented Oct 23, 2015 at 13:44
  • the xslt code is used to convert the text into email. I checked the result by checking the email received. Emails are HTML based Commented Oct 23, 2015 at 16:11
  • I am afraid that makes very little sense. Your actual output is "Hi, Jessica, &lt;br/&gt;&lt;br/&gt;Your account is activated!". An HTML browser would display this as Hi, Jessica, <br/><br/>Your account is activated! with no line breaks and the actual markup being shown. Commented Oct 23, 2015 at 17:12
  • Apologies, the code is entered through a jshell window so actually the '&lt;br/&gt;' will turn into <br/> when I see the actual code in my browser. Then our application will use the xslt code to convert and construct xml data. It is now working properly. It turns out it has nothing to do with my code but our application itself is misbehaving. Thanks everyone for the advice! Commented Oct 29, 2015 at 3:14

2 Answers 2

2

XSLT constructs a result tree, not a text file. That means outputting element nodes is very different from outputting text; in particular, you don't construct an element by creating the markup representation of the element. You can construct elements typically by using the xsl:element instruction, or if the name of the element is known in advance, using a "literal result element" which is an instruction that looks just like the element you want to create: in this case <br/>. So it's simple: to output a <br/> element, use the <br/> instruction.

So you start by outputting a text node:

<xsl:value-of select="concat(demessage/TEXT.1, demessage/TEXT.SPACE, demessage/TEXT.2"/>

then you output two element nodes:

<br/><br/>

and then another text node:

<xsl:value-of select="demessage/TEXT.3"/>
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to output a br element then you can't do that with a single value-of and concat, instead use <xsl:value-of select="concat(demessage/TEXT.1, demessage/TEXT.SPACE, demessage/TEXT.2)"/><br/><br/><xsl:value-of select="demessage/TEXT.3"/>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.