I have an XSLT file that is rendering an HTML page, I am trying to split the string by using ;
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:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<td width="50%" nowrap="nowrap">
<xsl:call-template name="split-parent" />
</td>
....
<xsl:template match="STUDENT_DETAILS/PARENT" name ="split-parent">
<xsl:variable name="splitParentsVar">
<xsl:call-template name="add-line-breaks">
<xsl:with-param name="stringToBreak" select="STUDENT_DETAILS/PARENT"/>
<xsl:with-param name="isEven" select="0"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$splitParentsVar"/>
</xsl:template>
<xsl:template name="add-line-breaks">
<xsl:param name="stringToBreak"/>
<xsl:param name ="isEven" />
<xsl:if test ="$isEven='1'">
<xsl:value-of select="concat($stringToBreak,'
')"/>
<xsl:if test="substring-after($stringToBreak,';')!=''">
<xsl:call-template name="add-line-breaks">
<xsl:with-param name="stringToBreak" select="substring-after($stringToBreak,';')"/>
<xsl:with-param name="isEven" select="0"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
<xsl:if test="$isEven='0'">
<xsl:value-of select="$stringToBreak"/>
<xsl:if test="substring-after($stringToBreak,';')!=''">
<xsl:call-template name="add-line-breaks">
<xsl:with-param name="stringToBreak" select="substring-after($stringToBreak,';')"/>
<xsl:with-param name="isEven" select="1"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
....
An example of the input would be:
George Aaron; Susan Lee Aaron; Richard Elliot Aaron; Albert Smith; Carry Johnson
output would be something like:
George Aaron; Susan Lee Aaron;
Richard Elliot Aaron; Albert Smith;
Carry Johnson
The input XML looks something like this:
<NewDataSet>
<REPORT_OPTIONS>
<RANK_RUN>12/04/2013</RANK_RUN>
<PRNT_WGHT_AVGE>False<PRNT_WGHT_RANK>
</REPORT_OPTIONS>
<STUDENT_DETAILS>
<STUD_PK>1590</STUD_PK>
<STUD_NAME>Robert SMith</STUD_NAME>
<PARENT>jubju Aaron; Susan Lee Aaron; Richard Elliot Aaron; Carl Smith</PARENT>
</STUDENT_DETAILS>
</NewDataSet>
I want to modify the <PARENT>
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).
Its an incomplete Input and Output XML. But the primary issue is that HTML and XHTML doesn't adhere to line breaks.
This code in XHTML:
Would be rendered as:
To insert a line break in HTML, you'll need to output a
<br/>
tag where you want line breaks in the output page.So you'd need to change this line:
to this:
Carried over from:
hInserting line-break into XML so that it appears after XSL rendering in VB.NET
You are (again) making it very difficult to help you, because there is no context - like where does the table begin, for example. Anyway, try fitting these two templates into your stylesheet: