Search code examples
xsltline-breaks

Add a new line in xslt


How to add a new line inside XSLT, i have already tried <xsl:text>&#xa;</xsl:text> but it didn't work, i also tried <xsl:text></xsl:text> it doesn't work everytime either. Isn't there another solution?
xml:

<composition>
            <ion type="positif">calcium 67.32mg/l</ion>
            <ion type="positif">magnésium 10.08mg/l</ion>
            <ion type="negatif">chlorure 20.82mg/l</ion>
            <ion type="negatif">nitrate 3.5mg/l</ion>
            <autre type="metal">fer</autre>
</composition>

xslt:

<tr>
    <xsl:for-each select="./bouteille/composition" >
      <td>
          <xsl:value-of select="./ion[@type='negatif']"/><xsl:text> <!-- Won't add a new line -->
           </xsl:text>
      </td>    
    </xsl:for-each>
</tr>

Solution

  • The example that you have posted is incomplete. The one thing that it makes clear, though, is that you are producing an HTML table. Therefore you should be using <br/> to create new lines within a table cell.

    Probably something like:

    <td>
        <xsl:for-each select="ion[@type='negatif']"/>
            <xsl:value-of select="."/>
            <br/>
        </xsl:for-each>
    </td>    
    

    I'm afraid I can't be more exact than that with no context to draw upon.