XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
john wwSubject: Limit description characters in XSLT transformation.
Author: john ww
Date: 06 Oct 2006 08:25 PM
Hi,
I really cant find this anywhere on the internet so I've come here and i hope someone can help. I can transform an XML so that only the most recent 3 (or any number) items display with a link in the title and a description underneath. At the moment the descriptions are short enough to be fully included.

What i would like to do now is to limit the size of the description displayed and have it end in ... . It can either be a certain number of characters or words.

e.g

Title with link
First # amounts of characters before...

I have used the itemsperpage variable but cant for the life of me think how to do the description. Its done in dreamweaver also.

Here is the XSLT

<xsl:for-each select="rss/channel/item[position() &lt;= $ItemsPerPage]">
<span class="bodytextsmall"><a href="{link}"><xsl:value-of select="title"/><br />
</a></span>
<span class="bodytext"><xsl:value-of select="description" disable-output-escaping="yes" /></span>...<br />
<br />
</xsl:for-each>

and here is the php.

<?php
//XMLXSL Transformation class
require_once('includes/MM_XSLTransform/MM_XSLTransform.class.php');
?><table width="160" border="0" cellspacing="0" cellpadding="3">
<tr>
<td><div align="left">
<?php
$mm_xsl = new MM_XSLTransform();
$mm_xsl->setXML("http://www.name.xml");
$mm_xsl->setXSL("rssfeeds/name.xsl");
$mm_xsl->addParameter("ItemsPerPage", "3");
echo $mm_xsl->Transform();
?>

Hope you can help

regards

John

Posttop
Tony LavinioSubject: Limit description characters in XSLT transformation.
Author: Tony Lavinio
Date: 07 Oct 2006 01:38 AM
Can you just change
<xsl:value-of select="description" disable-output-escaping="yes" />
to
<xsl:value-of select="concat(substring(description, 1, 100), '...')"/>

Do you really need 'disable-output-escaping'? The problem is if you
are truncating the content, and the stuff inside is HTML, you might
split a tag.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.