Not sure what I'm doing wrong here, but whatever I try I can't get either of the HTML truncation utilities to work. I managed to get this one from SO to work right off the bat, but unfortunately it seems to truncate each element within the node, as the content is formatted this means I get several truncated lines back, not what anyone needs. Edit: I managed to almost get this script working (from Allen, I later noticed!) however I'm getting 3 ellipses' after the truncation so it's clearly not working entirely as intended. The utilities hosted here look more robust, assuming I can get one to work.

My node looks like:

<content mode="formatted"><p><strong>But I must explain to you how all this mistaken</strong> idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally <em>encounter consequences</em> that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? <a href="http://#">But who has any right to find</a> fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</p>


  <p>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual</p>



And I'm calling it using:

<xsl:apply-templates select="content" mode="truncate" limit="50"/>

With HTML Truncate Advanced I'm just getting an unformatted version of the content back. Nothing is truncated. HTML Truncate returns nothing at all.

Neither utility really explains how to use it so not sure where else to turn.

Any advice?

EDIT: I gave up in the end and am using a user-defined excerpt (not always convenient, but in this case it's fine). Would be great to hear what I was doing wrong though, for the future.

@nathanhornby - What happens when you call it this way...

<xsl:apply-templates select="content/*" mode="truncate" limit="50"/>

I use this code to limit the length of a text. Maybe it is another starting point.

<xsl:template name="get-intro"> <xsl:param name="limit"/> <xsl:value-of select="substring(body, 1, $limit + string-length(substring-before(substring(body, $limit + 1),' ')))" disable-output-escaping="yes" /> <xsl:if test="string-length(body) &gt; $limit + 1" > <xsl:text> ...</xsl:text> </xsl:if> </xsl:template>

@bzerangue Actually I think I may have already been using content/* - I certainly tried it!

Very neat little utility @plenaforma - may give that one a go next time I need it!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details