Re: DOM and XSLTProcessor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4/9/07, Buesching, Logan J <ljbuesch@xxxxxxxxxx> wrote:
Greetings,



I apologize if this is a little long, but I am trying to put as much
information as I have done in this first post.  I am running PHP 5 and
attempting to use DOM to create data to show on a webpage and using
XSLTProcessor with an XSLT sheet to output it into XHTML.  Everything is
pretty fine an dandy until I wish to print raw text, such as xdebug and
var_dump.



My knowledge of DOM and XSLTProcessor is about a 5/10, such that I know
most basics, but not the more advanced things.  Whenever I try to add
data using createTextNode, it is always escaped, such that if I do
<strong>something</strong>, when shown to the screen, it shows
&lt;strong&gt; etc...



Here is the general outline:



<?php

$doc=new DOMDocument("1.0");

$root=$doc->createElement("root");

$wantedCode=$doc->createTextNode("<strong>Something</strong>");

$root->appendChild($wantedCode);

$doc->appendChild($root);

$proc=new XSLTProcessor;

$proc->importStylesheet(DOMDocument::load("test.xslt"));

echo $proc->transformToXML($doc);

?>



SomeSheet is something like:

<xsl:template match="/">

           <xsl:value-of select="."/>

</xsl:template>



The expected output that I would like to get is:

<strong>Something</strong>

(This would just bold my text, not literally see the <strong> tags).



The actual output is:

&lt;strong&gt;Something&lt;/strong&gt;

(This outputs the <strong> tags to the end user, which is what I do not
want).



I checked the manual at:
http://us3.php.net/manual/en/function.dom-domdocument-createtextnode.php
.  A user comment suggested to use CDATA nodes, so I attempted to change
my code to the following:



<?php

$doc=new DOMDocument("1.0");

$root=$doc->createElement("root");

//note the change right here

$wantedCode=$doc->createCDATASection("<strong>Something</strong>");

$root->appendChild($wantedCode);

$doc->appendChild($root);

$proc=new XSLTProcessor;

$proc->importStylesheet(DOMDocument::load("test.xslt"));

echo $proc->transformToXML($doc);



?>



But this was of no success; it just had the same output.



Is there anyone that is able to help me out here?



Thanks,

Logan


Try using htmlspecialchars_decode before outputting your data:
http://www.php.net/manual/en/function.htmlspecialchars-decode.php

Tijnema



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux