Tony Clifton Tony Clifton - 1 year ago 49
HTML Question

Add a linebreak in an HTML table via XSL

I transform an XML file to HTML via XSL.
In my html-table I have a column where I need to break the cell's content to a new line for each entry in one of my xml element-tags.

I'm not sure how to set up the xml-file for this.
Here's the output I was thinking of for my html-file:


and what doesn't work for me on the xsl-part:

<xsl:for-each select="info">
<xsl:value-of select="." /> <br/>

I've tried wrapping the lines in the xml with
but that didn't work. I think it's the xsl-part where I have the error. If I put a
after the value-of statement it will output everything and then add the
but of course I want the
for each entry.

I hope you can tell me of a way how to set this up correctly.

Answer Source

This transformation:

<xsl:stylesheet version="1.0"
 <xsl:output omit-xml-declaration="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="info/*[position() > 1]">
  <br /><xsl:text>&#xA;</xsl:text>
  <xsl:value-of select="."/>

when applied on the following XML document (as no source XML document is provided in the question):


produces the wanted result (<info> intentionally not generated as this isn't an HTML element):


Note 1: This transformation was verified to produce exactly the above result with all of my XSLT 1.0 and 2.0 processors: MSXML3, MSXML4, MSXML6, .NET XslCompiledTransform, .NET XslTransform, Saxon 6.5.4, XML-SPY, Saxon 9.1.05, XQSharp, AltovaXML2011 (XML-SPY for XSLT 2.0).

Note 2: If you really want to have the result wrapped int an <info> element, just add this template:

 <xsl:template match="info">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download