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).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…