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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + sort by variable (11)
-> + [XSLT Recursive Template Help]... (2)
-> + Adding values with document() ... (7)
-> + merging xml files in to single... (2)
-> - Limit description characters i... (2)
-> ->Limit description charact...
-> + problem parsing xml as text in... (2)
-> + Summarize/Distinct (5)
-> + unix epoch seconds to date str... (3)
-> + xml, xslt question (5)
-> + LGCL XSLT transformation (3)
-> + Dynamic include (3)
-> + .rdbxml as XML within Stylus ... (3)
-> + Array of Values From XSL (2)
-> + Problem Saving output (2)
-> + Base 64 encoded data embedded ... (2)
-> + XML-XML Mapping (2)
-> - Parameterized 'Document()' ...... (1)
-> + Newbie prob - Elements with sa... (3)
-> - .net 1.1 incorrectly processin... (1)
-> + xs:key and xs:keyref question (5)
-> + pass xsl-variable to javascrip... (2)
-- Previous [1321-1340] [1341-1360] [1361-1380] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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.

   
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.