NYCPHP Meetup

NYPHP.org

[nycphp-talk] Transforming XML with XSL (XsltProcessor problems)

Ben Sgro ben at projectskyline.com
Tue Mar 10 18:32:49 EDT 2009


Hello,

My PHP code is:
---------------------

        $xml = new DOMDocument;
        $xml->load($this->_payload);       

           $xsltProcessor = new XsltProcessor();
        $xsl = new DomDocument;
        $xsl->load('../lib/Transformations/text.xsl');
       
        $xsltProcessor->importStylesheet($xsl);
        $result = $xsltProcessor->transformToXml($xml);
   
        return $result;


My XSL is:
--------------

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
 xmlns="http://www.w3.org/1999/xhtml"
 >
<xsl:template match="/">
<xsl:element name="Data">
<xsl:element name="AccountNumber"><xsl:value-of 
select="//DataItem[@name='AccountNumber']/@value"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>


And my XML is:
---------------------

<ProfileRequest templateId="1" submitUser="asdf" 
submitDateTime="2009-01-12T17:32:46">
    <DataItem name="AccountNumber" value="600978"/>
</ProfileRequest>



The $result is:
-----------------

<?xml version="1.0"?>
<Data 
xmlns="http://www.w3.org/1999/xhtml"><AccountNumber></AccountNumber></Data>

So, as you can see the AccountNumber is missing. This XSL/XML works fine 
in Author (XML Tool).
Any ideas why this would fail? Also, the Xpath 
(//DataItem[@name='AccountNumber']/@value) works
if I make the XML a simpleXML object and call xpath on it.

Thanks for your help!

- Ben



More information about the talk mailing list