title: How to get the last index of a char in a string?
body: <p>I have the following task:<br>
  There is an xml element containing a long string. I need to use xsl to transform this element into a number of html <code>&lt;input&gt;</code> tags. It works like this: if the string is longer than an <code>&lt;input&gt;</code> field can hold without scrolling I call the same template recursively to create another input field with the remainig text.  </p>
  
  <p>The problem is that the string is often splitted right in the middle of the word which is not nice. </p>
  
  <p>So I need to find the position of the last <code>space</code> character that is not bigger than the size of the substring that fits into the <code>&lt;input&gt;</code> tag and print only the substring before it on the line.</p>
  
  <p>So I prepare a substring of max length, that can fit in the field, but I have no idea of how to get the index of the last <code>space</code> in it and pass it as a parameter into the next call of the function.</p>
  
  <p><strong>UPD:</strong> here is what I've got so far</p>
  
  <pre><code>&lt;xsl:template name="multilineInput"&gt;
      &lt;xsl:param name="input" select="."/&gt;
      &lt;xsl:param name="maxFirst" select="."/&gt;
      &lt;xsl:param name="firstLineWidth" select="."/&gt;
  
  
  
      &lt;input&gt;
          &lt;xsl:attribute name="readonly"&gt;readonly&lt;/xsl:attribute&gt;
          &lt;xsl:attribute name="class"&gt;input_multiline&lt;/xsl:attribute&gt;
          &lt;xsl:attribute name="style"&gt;width = "&lt;xsl:value-of select="$firstLineWidth"/&gt;"&lt;/xsl:attribute&gt;
          &lt;xsl:attribute name="type"&gt;text&lt;/xsl:attribute&gt;
          &lt;xsl:attribute name="value"&gt;&lt;xsl:value-of select="substring($input, 1, $maxFirst)"/&gt;&lt;/xsl:attribute&gt;
      &lt;/input&gt;
  
      &lt;xsl:if test="$maxFirst &amp;lt; string-length($input)"&gt;
          &lt;xsl:call-template name="multilineInput"&gt;
              &lt;xsl:with-param name="input" select="substring($input, $maxFirst+1, string-length($input)-$maxFirst)"/&gt;
              &lt;xsl:with-param name="maxFirst" select="110"/&gt;
              &lt;xsl:with-param name="firstLineWidth" select="'980'"/&gt;
          &lt;/xsl:call-template&gt;
      &lt;/xsl:if&gt;
  
  &lt;/xsl:template&gt;
  </code></pre>