I was wanting to craft a read more link using regex where it would cut the text at the nearest word with the entire string being less than X number of characters..
i was wondering how I'd use the following expression in xslt to get the right outcome:
I'd go with an xslt extension and write a static method which does what it needs to do, limiting text to 200 chars... Anyway, need to be aware that you'll have to parse the text as well, as it may contain links and html tags (if that's the case for you...).
Here's some code that may get you started (it's code taken from xslt search, so credits go to @drobar):
public string StripTagsRegex(string source) { return Regex.Replace(source, "<.*?>", string.Empty); }
Method will strip any html tags. And after that, make sure check for incomplete words (after limiting to 200 chars). Can use following code snippet for that:
Read More with regex
Hi Guys,
I was wanting to craft a read more link using regex where it would cut the text at the nearest word with the entire string being less than X number of characters..
i was wondering how I'd use the following expression in xslt to get the right outcome:
Tom,
I'd go with an xslt extension and write a static method which does what it needs to do, limiting text to 200 chars... Anyway, need to be aware that you'll have to parse the text as well, as it may contain links and html tags (if that's the case for you...).
Here's some code that may get you started (it's code taken from xslt search, so credits go to @drobar):
Method will strip any html tags. And after that, make sure check for incomplete words (after limiting to 200 chars). Can use following code snippet for that:
You can also use these functions inline in your xslt code, but there could be some performance issues when doing do.
Hope this helps.
Regards,
/Dirk
Hi Dirk! excellent thanks so much! looks like exactly what i need! :)
is working on a reply...