-2

I am passing string input parameter as below to XSLT,

passId=" Line1 | Line 2| Line3";

Accessing in XSLT as below :

<xsl:param name="passId"/>
<xsl:template match="/">
<html>
<head></head>
<xsl:value-of select="$passId"/>
<br/>
</html>
</xsl:template>

Expected output is in new line each:

Line1

Line2

Line3

How we achieve this output using XSLT template.

Actual input -- Line1 | Line 2| Line3";

Expected Output:

Line1

Line2

Line3

As above in XSLT all are printing in same line.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

If you are using the Xalan processor, you should be able to do:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:str="http://exslt.org/strings" extension-element-prefixes="str">

<xsl:param name="passId"/>

<xsl:template match="/">
    <html>
        <head/>
        <body>
            <xsl:for-each select="str:split($passId, '|')">
                <xsl:value-of select="." />
                <br/>
            </xsl:for-each>
        </body>
    </html>
</xsl:template>

</xsl:stylesheet>

With the parameter you are showing this will return:

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>Line1 <br> Line 2<br> Line3<br>
</body>
</html>
y.arazim
  • 866
  • 2
  • 10
  • y.arazim, I tried the step you mentioned above, But in sql db it shows below error while updating that template in column. Error as below. "Msg 402, Level 16, State 1, Line 1 The data types varchar and varchar are incompatible in the '|' operator. " Error from this line – Kesavan Balakrishnan Aug 25 '23 at 08:32
  • 1
    @KesavanBalakrishnan As I stated, this code is intended for the Xalan processor (which, AFAIK, is the default XSLT processor in Java). It should also work for any other processor that supports the str:split extension function. I don't know what "sql db" has to with XSLT processing at all. You were already asked to identify your XSLT processor, but you still haven't done so. – y.arazim Aug 25 '23 at 12:11