4 users online. Create an account or sign in to join them.Users

Search

A new XSLT utility, “HTML Truncate Advanced” is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.

This utility looks great but I’m having a tough time implementing it, no fault of yours, only my limited experience.

Could anyone share an example of this being used that I could see and maybe learn from?

Thanks!

<xsl:call-template name="truncate">
    <!-- path to the element containing HTML content
    e.g. a Textarea named "Comment" with Markdown enabled -->
    <xsl:with-param name="node" select="comment"/>
    <!-- words to truncate to -->
    <xsl:with-param name="limit" select="'100'"/>
</xsl:call-template>

Ahhh… thank you Nick.

This helps me finally understand call-template as well.

Much appreciated!

Just what I was looking for a few days ago.

“Solved” the problem by fetching the content of the first paragraph with <xsl:value-of select=”content/p[1]”/> instead to create previews of longer articles ;-)

Hi guys,

I’m trying to truncate a text (big text) inside a for each (it’s a news page), formatted by the rich text extension. I’ve tested it with low limits, worked perfectly. Buyt when I set the limit to 200 ( or above ), the utilitie doesn’t work properly, shorting the limit in some.

Does anyone knows if there is a problem when you use a limit like 200 or 250?

Thanks a lot!

<xsl:call-template name="truncate">
<xsl:with-param name="node" select="conteudo"/>
<xsl:with-param name="limit" select="'200'"/>
<xsl:with-param name="suffix" select="'...'"/></xsl:call-template>

I just ran into an issue where I had an image added at the top of an entry, so I needed a way to exclude the image from the text shown in the excerpt. The image was wrapped in a <p> element, so I also needed to make sure the empty element was not included. I came up with this change on line 165:

<xsl:template match="*" mode="truncate-render">
    <xsl:if test="text() != ''">
        <xsl:element name="{name()}">
            <xsl:apply-templates select="@*" mode="truncate-render" />
            <xsl:apply-templates select="*[name() != 'img'] | text()" mode="truncate-render" />
        </xsl:element>
    </xsl:if>
</xsl:template>

I just realized that the predicate that checks whether the node name() is img isn't necessary. img elements don't have text nodes, so the test for a node with no text() value already excludes img elements. So this can be simplified:

<xsl:template match="*" mode="truncate-render">
    <xsl:if test="text() != ''">
        <xsl:element name="{name()}">
            <xsl:apply-templates select="@*" mode="truncate-render" />
            <xsl:apply-templates select="* | text()" mode="truncate-render" />
        </xsl:element>
    </xsl:if>
</xsl:template>

hi,

Could anyone Please tell how to get only the text without applying styles at the time of using this utility. I am using content editor for adding the content, but i need only the text without applying the styles which added using the editor.

Now i am getting the text with styles like bold, italic, horizontal line, etc.,

thanks

I'm having some troubles with this one.

Given this XML:

<p>Villa Craiasa Branului (Wizard of Bran) is 4 bedroom newly built house 3km from Bran Castle, made famous in Bram Stoker’s Dracula novel. It set atop the heights of Predelut village, overlooking Bran, Zarnesti &amp; the valley of Brasov with beautiful views of the Transylvanian Alps including Piatra Craiului, the awesome Bucegi massive &amp; a host of other treats including orchards, forests &amp; plains.</p> 
<p>If you are looking for something special, why not come somewhere to get away from it all, to place equipped with everything you could need.  From a wood burner to a play station, from bicycles to Sun loungers, right through to feather-down bedding, pillows &amp; pure cotton sheets &amp; all the comforts you might wish in your own home have been accommodated.</p> 
<p><a>Bran</a> itself is a hugely underrated jewel in Romania’s crown. Without doubt, some of Europe’s finest scenery &amp; unchanged traditions lie here.  The most common response from travellers from all over the world is one of total unexpected surprise. Actual Transylvanian Romania &amp; its perception bear no comparison. Many outsiders have only seen the ruins of a former communist regime that devastated former historic cities. Not so in Bran. Much of it remains unchanged for many centuries.</p>

on calling the template:

<xsl:call-template name="truncate">
    <xsl:with-param name="node" select="path/to/content" />
    <xsl:with-param name="limit" select="900" />
</xsl:call-template>

I'm getting this out:

<p> 
    <p>Bran itself is a hugely underrated jewel in Romania’s crown. Without doubt, some of Europe’s finest scenery & unchanged traditions lie here.  The most…</p> 
</p>

Notice nested <p>. Any idea how to fix the utility?

I got the same issue, the truncated text start with the first nested tag and ends as it should, but the begining is not displayed. For me it s not a < a > but a < strong >.

I don't have this bug locally or on my demo server, but i have it on the final, so i imagine it s due to the server.

Any idea to solve this?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details