How to add line breaks (or returns) to a string on a XLST value-of select tag

76 Views Asked by At

I have a XLST transformation code that get values from a list of elements

  <NewSourceName>
    <xsl:for-each select="CORRELATION/EXPLOITS/EXPLT_SRC/EXPLT_LIST/EXPLT">
      <xsl:variable name="Source" select="../../SRC_NAME"/>
      <xsl:variable name="Link" select="LINK"/>
      <xsl:variable name="Description" select="DESC"/>
      <xsl:variable name="Reference" select="REF"/>
      <xsl:value-of select="concat('Source: ',$Source,' Reference: ',$Reference,' Description: ',$Description,' Link: ',$Link,' ')"/>
    </xsl:for-each>
  </NewSourceName>

This code generate the output text I need:

Source: The Exploit-DB Reference: CVE-2020-14882 Description: Oracle WebLogic Server 12.2.1.0 - RCE (Unauthenticated) - The Exploit-DB Ref : 49479 Link: http://www.exploit-db.com/exploits/49479 Source: The Exploit-DB Reference: CVE-2020-11022 Description: jQuery 1.2 - Cross-Site Scripting (XSS) - The Exploit-DB Ref : 49766 Link: http://www.exploit-db.com/exploits/49766 

I did try to add \n or <BR> to the string to add line breaks to get this format on the "rich text field" in a RSA Archer Text Field, but when the transformation is processed returns an error.

<xsl:value-of select="concat('<BR>Source: ',$Source,'\n Reference: ',$Reference,' Description: ',$Description,' Link: ',$Link,' ')"/>

I need the text looks like this

<p>Source: The Exploit-DB<br> 
Reference: CVE-2020-14882<br> 
Description: Oracle WebLogic Server 12.2.1.0 - RCE (Unauthenticated) - The Exploit-DB Ref : 49479<br> 
Link: http://www.exploit-db.com/exploits/49479 </p>
<br>
<p>Source: The Exploit-DB <br>
Reference: CVE-2020-11022 <br>
Description: jQuery 1.2 - Cross-Site Scripting (XSS) - The Exploit-DB Ref : 49766 <br>
Link: http://www.exploit-db.com/exploits/49766<p>

Any idea?

1

There are 1 best solutions below

0
On

A line break in HTML is an element, not text. To get the result you show, you need to do something like:

<xsl:for-each select="CORRELATION/EXPLOITS/EXPLT_SRC/EXPLT_LIST/EXPLT">
    <p>
        <xsl:text>Source: </xsl:text>
        <xsl:value-of select="../../SRC_NAME"/>
        <br/>
        <xsl:text>Reference: </xsl:text>
        <xsl:value-of select="REF"/>
        <br/>
        <xsl:text>Description: </xsl:text>
        <xsl:value-of select="DESC"/>
        <br/>
        <xsl:text>Link: </xsl:text>
        <xsl:value-of select="LINK"/>
    </p>
</xsl:for-each>

Untested, because no reproducible example to test with was provided.