
I hope I am not abusing this list in asking occasionally for advice on the best way to hack something in xslt. 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. Here's where I got to so far: <xsl:template match="t:p"> <xsl:variable name="pString"> <xsl:value-of select="."/> </xsl:variable> <xsl:for-each select="tokenize($pString, '\.\s')"> <xsl:variable name="seq"> <xsl:value-of select="string(position())"/> </xsl:variable> <xsl:variable name="wordsSoFar"> <xsl:value-of select="string-length(translate(normalize-space (preceding-sibling::text()), ' ', '')) + 1"/> </xsl:variable> <xsl:if test="$wordsSoFar < $maxWords"> <s n="{$seq}"> <xsl:value-of select="."/> </s> <xsl:if> </xsl:for-each> </xsl:template> But this is not valid because preceding-sibling:: wants a node() not a string (even though "text()" *is* a node imho). Am I going about this entirely the wrong way?