Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to add line breaks inside a template in XSLT
    text
    copied!<p>I have an XSLT file that is rendering an HTML page, I am trying to split the string by using <code>;</code> as the delimiter and then adding line breaks every EVEN break. I have my code below, it doesn't seem to work, the line breaks don't appear:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;td width="50%" nowrap="nowrap"&gt; &lt;xsl:call-template name="split-parent" /&gt; &lt;/td&gt; .... &lt;xsl:template match="STUDENT_DETAILS/PARENT" name ="split-parent"&gt; &lt;xsl:variable name="splitParentsVar"&gt; &lt;xsl:call-template name="add-line-breaks"&gt; &lt;xsl:with-param name="stringToBreak" select="STUDENT_DETAILS/PARENT"/&gt; &lt;xsl:with-param name="isEven" select="0"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:variable&gt; &lt;xsl:value-of select="$splitParentsVar"/&gt; &lt;/xsl:template&gt; &lt;xsl:template name="add-line-breaks"&gt; &lt;xsl:param name="stringToBreak"/&gt; &lt;xsl:param name ="isEven" /&gt; &lt;xsl:if test ="$isEven='1'"&gt; &lt;xsl:value-of select="concat($stringToBreak,'&amp;#xa;')"/&gt; &lt;xsl:if test="substring-after($stringToBreak,';')!=''"&gt; &lt;xsl:call-template name="add-line-breaks"&gt; &lt;xsl:with-param name="stringToBreak" select="substring-after($stringToBreak,';')"/&gt; &lt;xsl:with-param name="isEven" select="0"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;/xsl:if&gt; &lt;xsl:if test="$isEven='0'"&gt; &lt;xsl:value-of select="$stringToBreak"/&gt; &lt;xsl:if test="substring-after($stringToBreak,';')!=''"&gt; &lt;xsl:call-template name="add-line-breaks"&gt; &lt;xsl:with-param name="stringToBreak" select="substring-after($stringToBreak,';')"/&gt; &lt;xsl:with-param name="isEven" select="1"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; .... </code></pre> <p>An example of the input would be:</p> <p>George Aaron; Susan Lee Aaron; Richard Elliot Aaron; Albert Smith; Carry Johnson</p> <p>output would be something like:</p> <p>George Aaron; Susan Lee Aaron; <br/>Richard Elliot Aaron; Albert Smith; <br/> Carry Johnson</p> <p>The input XML looks something like this:</p> <pre><code>&lt;NewDataSet&gt; &lt;REPORT_OPTIONS&gt; &lt;RANK_RUN&gt;12/04/2013&lt;/RANK_RUN&gt; &lt;PRNT_WGHT_AVGE&gt;False&lt;PRNT_WGHT_RANK&gt; &lt;/REPORT_OPTIONS&gt; &lt;STUDENT_DETAILS&gt; &lt;STUD_PK&gt;1590&lt;/STUD_PK&gt; &lt;STUD_NAME&gt;Robert SMith&lt;/STUD_NAME&gt; &lt;PARENT&gt;jubju Aaron; Susan Lee Aaron; Richard Elliot Aaron; Carl Smith&lt;/PARENT&gt; &lt;/STUDENT_DETAILS&gt; &lt;/NewDataSet&gt; </code></pre> <p>I want to modify the <code>&lt;PARENT&gt;</code> tag so that every two parents there is a line break that will be rendered in HTML (Whatever the best way to do this is).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload