Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can split the text into words by inserting zero-width space characters (U+200B, HTML entity &amp;#x200b), then the line breaks will occur at these positions:</p> <pre><code>&lt;xsl:template name="split_value"&gt; &lt;xsl:param name="value"/&gt; &lt;xsl:param name="max_length"/&gt; &lt;xsl:variable name="ret"&gt; &lt;xsl:value-of select="substring($value, 1, $max_length)"/&gt; &lt;xsl:if test="string-length($value) &amp;gt; $max_length"&gt; &lt;xsl:value-of select="'&amp;#x200b;'"/&gt; &lt;xsl:call-template name="split_value"&gt; &lt;xsl:with-param name="value" select="substring($value, $max_length + 1)" /&gt; &lt;xsl:with-param name="max_length" select="$max_length" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;/xsl:variable&gt; &lt;xsl:value-of select="$ret"/&gt; &lt;/xsl:template&gt; </code></pre> <p><strong>Note: you might want to enhance the template so that it splits only pieces of text where no whitespace occurs between $max_length continuous characters.</strong></p> <hr> <p>Here's a test case.</p> <p>Input XML:</p> <pre><code>&lt;data&gt;0123456789&lt;/data&gt; </code></pre> <p>Stylesheet (generates HTML):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl" &gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;body style="font-family: Arial; font-size: 12pt; font-weight: normal" &gt; &lt;table width="4cm"&gt; &lt;xsl:for-each select="/data"&gt; &lt;tr&gt;&lt;td&gt; &lt;xsl:call-template name="split_value"&gt; &lt;xsl:with-param name="value" select="text()" /&gt; &lt;xsl:with-param name="max_length" select="number(4)" /&gt; &lt;/xsl:call-template&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload