<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#CCCCCC">
    <p>I hope I am not abusing this list in asking occasionally for
      advice on the best way to hack something in xslt. <br>
    </p>
    <p>Today's problem is to output only the first x sentences (string
      terminated by a full stop) of a paragraph such that the total
      number of words (space delimited strings)  is less than some limit
      (call it $maxWords) Since the sentences are of variable length,
      obviously I don't know what x is.<br>
    </p>
    <p>Here's where I got to so far:</p>
    <p><xsl:template match="t:p"><br>
              <xsl:variable name="pString"><br>
                  <xsl:value-of select="."/><br>
              </xsl:variable><br>
              <xsl:for-each select="tokenize($pString, '\.\s')"><br>
                  <xsl:variable name="seq"><br>
                      <xsl:value-of select="string(position())"/><br>
                  </xsl:variable><br>
                  <xsl:variable name="wordsSoFar"><br>
                      <xsl:value-of
      select="string-length(translate(normalize-space<br>
                      (preceding-sibling::text()), ' ', '')) + 1"/><br>
                  </xsl:variable><br>
                <xsl:if test="$wordsSoFar &lt; $maxWords"></p>
    <p>            <s n="{$seq}"><br>
                      <xsl:value-of select="."/><br>
                  </s></p>
    <p>          <xsl:if></p>
    <p>        </xsl:for-each><br>
          </xsl:template><br>
    </p>
    <p>But this is not valid because preceding-sibling:: wants a node()
      not a string (even though "text()" *is* a node imho). <br>
    </p>
    <p>Am I going about this entirely the wrong way?</p>
    <p><br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
  </body>
</html>