One thing I have told a lot of people to do if they are having
issues with this function is to check for any 'xmlns' attributes
that get generated and added to your xml pages by some
types of popular software.
<?php
$file = "http://data.map***.net/m***ck.asmx/GetMessages?IMEI=$id";
$docxml = file_get_contents($file);
//You may have to do something like this where
//I remove any instance of xmlns tags that get
//returned by my ASP.NET SOAP responses.
$docxml =
str_replace("xmlns=\"http://data.map***.net/m***ck.asmx?WSDL\"",
"",$docxml);
$xslt = new xsltProcessor;
//You don't remove them then this function will blow up.
$xslt->registerPHPFunctions();
$xslt->importStyleSheet(DomDocument::load('../xsl/message.xsl'));
print $xslt->transformToXML(DomDocument::loadXML($docxml));
?>
Also a few cool tricks with this function is that you can call
built in PHP functions. For example:
<xsl:value-of
select="php:function('nl2br',string(MessageContent/Message))"
disable-output-escaping="yes"/>
That XSL value will now return your normal string but replace
all your new line charactors in your xml with '<br />'s.
Also note the 'disable-output-escaping="yes"' statement. If
you don't call this, then the output of that bind will be ran
thru basicly a "htmlencode()" type function.
Last but not least, take a look at the 'string()' function I
called in XSL before passing it back. That is because without
calling that, when it runs it will try and pass the node object,
and not its value (which is what you most likely only want).
This function is very awsome and could lead to some very
interesting code development. Skins could be loaded
remotely. You could write an RSS viewer in PHP without much
code. You could parse XHTML pages into another view (either
localy or remotely). Then you can take that same XML
content and throw it against ASP.NET, Java, or even a
command line processing tool using that same exact XSL
style sheet and generate the front ends for you page without
much change. I'm very excited.
Happy codding.