<div dir="ltr">Hi Lou,<div><br></div><div>Would it make sense to use xsl:for-each-group to group the sentences into <s> units to make this easier? Then I'd probably recursively call a template or function passing the current collection of <s> units as a variable item* value, testing if its tokenised number is above or below $maxWords. </div><div><br></div><div>Not got time to write that out as a solution atm, and I'm sure it can be done without the recursivity as well, but that is the approach that would have occurred to me at least.</div><div><br></div><div>-James</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 5 Nov 2018 at 12:03, Lou Burnard <<a href="mailto:lou.burnard@retired.ox.ac.uk">lou.burnard@retired.ox.ac.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div 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 < $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>
</div>
_______________________________________________<br>
oXygen-user mailing list<br>
<a href="mailto:oXygen-user@oxygenxml.com" target="_blank">oXygen-user@oxygenxml.com</a><br>
<a href="https://www.oxygenxml.com/mailman/listinfo/oxygen-user" rel="noreferrer" target="_blank">https://www.oxygenxml.com/mailman/listinfo/oxygen-user</a><br>
</blockquote></div>