note 76392 added to ref.xslt

From: Date: Fri, 13 Jul 2007 05:27:32 +0000
Subject: note 76392 added to ref.xslt
Groups: php.notes 
Request: Send a blank email to php-notes+get-128427@lists.php.net to get a copy of this message
The XSLTProcessor, when transforming a document, always resolves entities. To avoid this (if you want to keep HTML entitities by ex.), you have two solutions: - if you have full control over the input document, you can encapsulate every text element which contains entities in a CDATA section. - the previous solution is the smarter and the less computing intensive, but it is not always possible. In other cases, what you can do is to replace every occurence of '&' (entity mark) by something which will be considered as normal text by the parser (let's say '[AMP]' by ex) in the input document before the transformation. After the transformation, you can get these entitites back in the output document by reversing the previous operation. <?php $xml = $input_dom->saveXML(); $xml = str_replace('&', '[AMP]', $xml); $input_dom->loadXML($xml); $xml = $xsl->transformToXML($input_dom); $xml = str_replace('[AMP]', '&', $xml); $output_dom->loadXML($xml); ?> Warning : this second method "escapes" ALL entities, even those you wouldn't want to be escaped. This is a raw explanation, fine-tune it to your own situation. ---- Server IP: 217.174.196.197 Probable Submitter: 90.31.38.98 ---- Manual Page -- http://www.php.net/manual/en/ref.xslt.php Edit -- https://master.php.net/note/edit/76392 Del: integrated -- https://master.php.net/note/delete/76392/integrated Del: useless -- https://master.php.net/note/delete/76392/useless Del: bad code -- https://master.php.net/note/delete/76392/bad+code Del: spam -- https://master.php.net/note/delete/76392/spam Del: non-english -- https://master.php.net/note/delete/76392/non-english Del: in docs -- https://master.php.net/note/delete/76392/in+docs Del: other reasons-- https://master.php.net/note/delete/76392 Reject -- https://master.php.net/note/reject/76392 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128427) next »