New to XSLT, and have an XML field with unicode line feed characters (
) which I need to display with HTML line breaks.
In my XML there is a "parameters" field includes line feeds as separators for multiple values, but they are not being read as such. In the fourth line, userColumn index="54" the "parameters" field has a value of "YES No Possible" which should be output as three lines showing a word on each line...
My Table Definition:
<table>
<tr bgcolor="#6FB6E2">
<th>User Field</th>
<th>Name</th>
<th>Identifier</th>
<th>Type</th>
<th>Parameters</th>
<th>Locked</th>
<th>Mandatory</th>
</tr>
<xsl:for-each select="PREFERENCES/USERCOLUMNS/userColumn">
<tr>
<td>USER<xsl:value-of select="@index"/></td>
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="@identifier"/></td>
<td><xsl:value-of select="@type"/></td>
<td><xsl:value-of select="@parameters"/></td>
<td><xsl:value-of select="@locked"/></td>
<td><xsl:value-of select="@mandatory"/></td>
</tr>
</xsl:for-each>
</table>
My Sample XML:
<?xml version='1.0' encoding='UTF-8' standalone='yes'?><PREFERENCES>
<USERCOLUMNS count="168">
<userColumn index="33" identifier="user.custom.language" name="Language" locked="false" mandatory="false" type="1"/>
<userColumn index="41" identifier="user.basic.host.presenter" name="Host/Presenter" locked="false" mandatory="false" type="2"/>
<userColumn index="42" identifier="user.basic.subject.line" name="Subject/Line" locked="false" mandatory="false" type="3"/>
<userColumn index="54" identifier="user.extended.best.take" name="Best Take" parameters="YES No Possible" locked="false" mandatory="false" type="4"/>
<userColumn index="55" identifier="user.basic.shoot.date" name="Shoot Date" locked="false" mandatory="false" type="5"/>
</USERCOLUMNS>
</PREFERENCES>
Proposed XSLT from contributor Viorel_ ALMOST works...:
<xsl:template name="show-lines"><xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, ' ')">
<xsl:value-of select="substring-before($text, ' ')"/>
<br/>
<xsl:call-template name="show-lines">
<xsl:with-param name="text" select="substring-after($text, ' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The parameters value shows up in HTML as:
Sunny0;Cloudy0;Rain0;Wind0;Snow0;Ice0;Fog
But it should show up as:
Sunny
Cloudy
Rain
Wind
Snow
Ice
Fog
Is there anyway to have the table word wrap on output so that line feeds are correctly interpreted and displayed as breaks? Thanks!!