Truncating text with escaped HTML
This is an open discussion with 2 replies, filed under XSLT.
Search
The XSLT utility expects an XML node to be passed. Your DS returns escaped data, thus it is treated as a very long string, hence your result. Somehow, you must return unescaped content in your datasource. Some custom PHP should do it.
sigh I was afraid you might say that. :D
I replaced the call to include
in my datasource with this monster:
$classParams = get_object_vars($this); foreach($classParams as $key => $value) { $dynamicXML->$key = $value; } $result = $dynamicXML->execute($param_pool); $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadXML($result->generate()); $reviews = $doc->documentElement->getElementsByTagName('user_review'); foreach($reviews as $r) { $f = $doc->createDocumentFragment(); $f->appendXML('<user_review>' . str_replace('&', '&', $r->nodeValue) . '</user_review>'); $r->parentNode->replaceChild($f, $r); } return $doc->saveXML($doc->documentElement);
It’s ugly. But it works. Thanks for pointing me in the right direction.
Create an account or sign in to comment.
I’m pulling in some text from an RSS feed that contains escaped HTML (e.g.,
<em>
is<em>
.I’m trying to use the HTML Truncate Advanced utility to truncate this text to a 500 characters (give or take) teaser. However, occasionally it produces some very bizarre results. In the case I’m struggling with now, it outputs unescaped HTML (which is fine by me), but the output is broken.
I’ve tried creating an xpathr gist with the node in question, but xpathr itself didn’t want to process it. On my local server, this is what I see in the HTML source:
Can I pre-process this node before I send it to the utility, or can I tweak the truncate utility to handle this somehow?